18 require_once SQ_CORE_PACKAGE_PATH.
'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
20 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
59 parent::__construct($assetid);
77 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
78 if (!system_asset_fns_create_pre_check($this)) {
81 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
82 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
84 if ($linkid = parent::create($link)) {
85 if (!system_asset_fns_create_cleanup($this)) {
91 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
93 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
96 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
113 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
144 trigger_localised_error(
'CRON0024', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
185 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
187 $assetids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form', FALSE);
190 $filepath = $this->data_path.
'/warning_assets.php';
191 if (is_file($filepath)) {
192 $warning_assetids = require_once($filepath);
193 if (!is_array($warning_assetids)) {
194 $warning_assetids = Array();
197 $warning_assetids = Array();
200 foreach ($assetids as $assetid) {
201 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
205 $parent_assetids = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($assetid);
207 $parent_assetid = reset($parent_assetids);
209 $form_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($parent_assetid);
212 $incomplete_subs_folder = $asset->getSubmissionsFolder(
'incomplete_submissions');
214 if ($incomplete_subs_folder) {
216 $remove_period = $asset->attr(
'submission_expiry_time');
218 if ($remove_period > 0) {
221 $sql =
'SELECT DISTINCT
225 ON a.assetid = l.minorid
227 l.majorid = :majorid AND
228 a.created < '.$date_sql;
235 foreach($submission_assetids as $submission_record) {
236 $submission_assetid = $submission_record[
'assetid'];
237 $submission_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($submission_assetid);
239 $GLOBALS[
'SQ_SYSTEM']->am->trashAsset($submission_assetid);
240 $submission_asset->delete(FALSE);
243 $path = $asset->data_path.
'/incomplete_attachments/s'.$submission_assetid;
245 delete_directory($path);
248 unset($submission_asset);
254 $warning_period = $asset->attr(
'submission_warning_time');
256 if ($warning_period > 0) {
257 $email_format = $asset->getAttribute(
'warning_email_format');
260 $sql =
'SELECT DISTINCT
264 ON a.assetid = l.minorid
266 l.majorid = :majorid AND
267 a.created < '.$date_sql;
274 foreach($submission_assetids as $submission_record) {
275 $submission_assetid = $submission_record[
'assetid'];
276 $submission_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($submission_assetid);
278 if(empty($submission_asset))
continue;
280 $created_userid = $submission_asset->created_userid;
282 if (!isset($warning_assetids[$submission_assetid])) {
285 $previous_value = $current_value = unserialize($email_format->value);
286 $current_value[
'to_assetids'][] = $created_userid;
289 $keywords = $email_format->getKeywords();
290 $replacements = Array();
292 foreach ($keywords as $keyword) {
296 case 'form_submission_url_id' :
297 $replacement = $submission_assetid;
300 case 'form_total_pages' :
301 $replacement = $asset->getTotalPages();
304 case 'return_to_form_url_current' :
305 $replacement = $form_url.
'?SQ_FORM_'.$asset->id.
'_SUBMISSION='.$submission_assetid.
'&SQ_FORM_'.$asset->id.
'_PAGE='.$submission_asset->attr(
'current_page');
308 case 'return_to_form_url_latest' :
309 $replacement = $form_url.
'?SQ_FORM_'.$asset->id.
'_SUBMISSION='.$submission_assetid.
'&SQ_FORM_'.$asset->id.
'_PAGE='.$submission_asset->attr(
'latest_page');
313 if (substr($keyword, 0, 11) ===
'form_asset_') {
315 $sub_keyword = substr($keyword, 11);
316 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_assetid);
317 if(empty($parent_asset))
continue;
318 $replacement = $parent_asset->getKeywordReplacement(
'asset_'.$sub_keyword);
319 }
else if (substr($keyword, 0, 11) ===
'user_asset_') {
321 $sub_keyword = substr($keyword, 11);
322 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($created_userid);
323 if(empty($user))
continue;
324 $replacement = $user->getKeywordReplacement(
'asset_'.$sub_keyword);
325 }
else if (substr($keyword, 0, 17) ===
'submission_asset_') {
327 $sub_keyword = substr($keyword, 17);
328 $replacement = $submission_asset->getKeywordReplacement(
'asset_'.$sub_keyword);
333 if ($replacement !== NULL) {
334 $replacements[$keyword] = $replacement;
338 $email_format->setValue(serialize($current_value));
339 $email_format->sendMail($replacements);
340 $email_format->setValue(serialize($previous_value));
342 $warning_assetids[$submission_assetid] = TRUE;
345 unset($submission_asset);
356 if (!empty($warning_assetids)) {
358 $asset_attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'complete',
'form_submission', array_keys($warning_assetids));
360 foreach ($warning_assetids as $warning_assetid => $dummy) {
361 if (!isset($asset_attrs[$warning_assetid])) {
364 unset($warning_assetids[$warning_assetid]);
366 }
else if ($asset_attrs[$warning_assetid] === 1) {
368 unset($warning_assetids[$warning_assetid]);
377 create_directory($this->data_path);
378 string_to_file(
'<'.
'?php return '.var_export($warning_assetids, TRUE).
'?'.
'>', $filepath);
379 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
381 return SQ_CRON_JOB_COMPLETED;
398 $res = parent::run();
399 if ($res & SQ_CRON_JOB_REMOVE) {
400 $res = $res - SQ_CRON_JOB_REMOVE;