foreach ($languages as $language) { $subjects[$language->getCode()] = $language->getMessage(MESSAGE_PAGE_ACTION_EMAIL_ARCHIVE_SUBJECT); $bodies[$language->getCode()] = $language->getMessage(MESSAGE_EMAIL_VALIDATION_AWAITS) . "\n" . $language->getMessage(MESSAGE_PAGE_ACTION_EMAIL_ARCHIVE_BODY, array($cms_page->getTitle() . ' (ID : ' . $cms_page->getID() . ')', $cms_user->getFullName())); } break; } break; } $potentialValidators = CMS_profile_usersCatalog::getValidators(MOD_STANDARD_CODENAME); $validators = array(); foreach ($potentialValidators as $aPotentialValidator) { if ($aPotentialValidator->hasPageClearance($cms_page->getID(), CLEARANCE_PAGE_EDIT)) { $validators[] = $aPotentialValidator; } } $group_email->setUserMessages($validators, $bodies, $subjects, ALERT_LEVEL_VALIDATION, MOD_STANDARD_CODENAME); $group_email->sendMessages(); } else { $validation = new CMS_resourceValidation(MOD_STANDARD_CODENAME, $edited, $cms_page); $mod = CMS_modulesCatalog::getByCodename(MOD_STANDARD_CODENAME); $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT); } } } //log event if ($logAction) { $log = new CMS_log(); $log->logResourceAction($logAction, $cms_user, MOD_STANDARD_CODENAME, $cms_page->getStatus(), "", $cms_page); } } $view->show();
/** * Module script task * @param array $parameters the task parameters * task : string task to execute * object : string module codename for the task * field : string module uid * ... : optional field relative parameters * @return Boolean true/false * @access public */ function scriptTask($parameters) { //if script concern a field, pass to it if (isset($parameters['field']) && sensitiveIO::isPositiveInteger($parameters['field'])) { if (!is_object($this->_objectValues[$parameters['field']]) || !method_exists($this->_objectValues[$parameters['field']], 'scriptTask')) { return false; } //then pass task to field return $this->_objectValues[$parameters['field']]->scriptTask($parameters); } else { //this is an object related script switch ($parameters['task']) { case 'emailNotification': //instanciate user $user = CMS_profile_usersCatalog::getByID($parameters['validator']); if ($this->userHasClearance($user, CLEARANCE_MODULE_EDIT)) { //get Object definition $objectDef = $this->getObjectDefinition(); //get module $codename = CMS_poly_object_catalog::getModuleCodenameForObjectType($objectDef->getID()); switch ($parameters['type']) { case 'validate': $group_email = new CMS_emailsCatalog(); $languages = CMS_languagesCatalog::getAllLanguages(); $subjects = array(); $bodies = array(); //editors $editorsIds = $parameters['editors']; $editors = array(); foreach ($editorsIds as $editorId) { $editor = CMS_profile_usersCatalog::getByID($editorId); if (is_a($editor, 'CMS_profile_user') && !$editor->hasError()) { $editors[] = $editor; } } //$editors = $this->getEditors(); $editorsInfos = ''; foreach ($editors as $editor) { $editorsInfos .= $editorsInfos ? ",\n" : ''; $editorsInfos .= $editor->getFullName() . ($editor->getEmail() ? ' (' . $editor->getEmail() . ')' : ''); } foreach ($languages as $language) { $subjects[$language->getCode()] = $language->getMessage(self::MESSAGE_POLYMOD_ACTION_EMAIL_SUBJECT, array($objectDef->getLabel($language)), MOD_POLYMOD_CODENAME); $bodies[$language->getCode()] = $language->getMessage(MESSAGE_EMAIL_VALIDATION_AWAITS) . "\n" . $language->getMessage(self::MESSAGE_POLYMOD_ACTION_EMAIL_BODY, array($objectDef->getLabel($language), $this->getLabel(), $editorsInfos), MOD_POLYMOD_CODENAME); } $group_email->setUserMessages(array($user), $bodies, $subjects, ALERT_LEVEL_VALIDATION, $codename); $group_email->sendMessages(); break; case 'delete': $group_email = new CMS_emailsCatalog(); $languages = CMS_languagesCatalog::getAllLanguages(); $subjects = array(); $bodies = array(); //editors $editorsIds = $parameters['editors']; $editors = array(); foreach ($editorsIds as $editorId) { $editor = CMS_profile_usersCatalog::getByID($editorId); if (is_a($editor, 'CMS_profile_user') && !$editor->hasError()) { $editors[] = $editor; } } //$editors = $this->getEditors(); $editorsInfos = ''; foreach ($editors as $editor) { $editorsInfos .= $editorsInfos ? ",\n" : ''; $editorsInfos .= $editor->getFullName() . ($editor->getEmail() ? ' (' . $editor->getEmail() . ')' : ''); } foreach ($languages as $language) { $subjects[$language->getCode()] = $language->getMessage(self::MESSAGE_POLYMOD_ACTION_EMAIL_DELETE_SUBJECT, array($objectDef->getLabel($language)), MOD_POLYMOD_CODENAME); $bodies[$language->getCode()] = $language->getMessage(MESSAGE_EMAIL_VALIDATION_AWAITS) . "\n" . $language->getMessage(self::MESSAGE_POLYMOD_ACTION_EMAIL_DELETE_BODY, array($objectDef->getLabel($language), $this->getLabel(), $editorsInfos), MOD_POLYMOD_CODENAME); } $group_email->setUserMessages(array($user), $bodies, $subjects, ALERT_LEVEL_VALIDATION, $codename); $group_email->sendMessages(); break; default: $this->raiseError('Unknown script task to do : ' . print_r($parameters, true)); return false; break; } } return true; break; default: $this->raiseError('Unknown script task to do : ' . print_r($parameters, true)); return false; break; } } }
/** * Process the daily routine reminders part : send reminders to users * * @return void * @access private */ protected function _dailyRoutineReminders() { $today = new CMS_date(); $today->setNow(); $sql = "\n\t\t\tSELECT\n\t\t\t\tid_pag,\n\t\t\t\tremindedEditorsStack_pag,\n\t\t\t\treminderOnMessage_pbd\n\t\t\tFROM\n\t\t\t\tpages, pagesBaseData_public\n\t\t\tWHERE\n\t\t\t\tpage_pbd = id_pag\n\t\t\t\tAND (\n\t\t\t\t\t(lastReminder_pag < reminderOn_pbd\n\t\t\t\t\tAND\n\t\t\t\t\t'" . $today->getDBValue() . "' >= reminderOn_pbd)\n\t\t\t\t\tOR (\n\t\t\t\t\t\t(to_days('" . $today->getDBValue() . "') - to_days(lastReminder_pag)) >= reminderPeriodicity_pbd\n\t\t\t\t\t\tAND\n\t\t\t\t\t\treminderPeriodicity_pbd != '0'\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t"; $q = new CMS_query($sql); $reminders = array(); while ($data = $q->getArray()) { $reminders[] = $data; } //send the emails foreach ($reminders as $reminder) { //instanciate page and update its lastReminder vars $page = CMS_tree::getPageByID($reminder["id_pag"]); $page->touchLastReminder(); $page->writeToPersistence(); //build users array $users_stack = new CMS_stack(); $users_stack->setTextDefinition($reminder["remindedEditorsStack_pag"]); $users_stack_elements = $users_stack->getElements(); $users = array(); foreach ($users_stack_elements as $element) { $usr = CMS_profile_usersCatalog::getByID($element[0]); if ($usr instanceof CMS_profile_user) { $users[$element[0]] = $usr; } } if (!$users) { continue; } //prepare emails and send them $group_email = new CMS_emailsCatalog(); $languages = CMS_languagesCatalog::getAllLanguages(); $subjects = array(); $bodies = array(); foreach ($languages as $language) { $subjects[$language->getCode()] = $language->getMessage(self::MESSAGE_MOD_STANDARD_EMAIL_REMINDER_SUBJECT); $bodies[$language->getCode()] = $language->getMessage(self::MESSAGE_MOD_STANDARD_EMAIL_REMINDER_BODY, array($page->getTitle() . " (ID : " . $page->getID() . ")")) . "\n" . $language->getMessage(self::MESSAGE_MOD_STANDARD_EMAIL_REMINDER_BODY_MESSAGE, array($reminder["reminderOnMessage_pbd"])); } $group_email->setUserMessages($users, $bodies, $subjects, ALERT_LEVEL_PAGE_ALERTS, MOD_STANDARD_CODENAME); $group_email->sendMessages(); } }