/**
 * This function encapsulate a set of common instruction for event notification generation
 * @param string 				$class 			The class name ho event (eg. UserMod)
 * @param string 				$module			The module generator (eg. directory)
 * @param string 				$section 		The section in module that generate event (eg. edit)
 * @param int	 				$priority		The priority level of event
 * @param string 				$description 	The description of the event
 * @param array	 				$recipients 	An array of userid that should be notified
 * @param EventMessageComposer 	$msg_composer 	a class for message composition
 * @param bool					$force_email_send		if true the message is sent to all the user in $recipients ignoring their settings for email
 **/
function createNewAlert($class, $module, $section, $priority, $description, $recipients, $msg_composer, $force_email_send = false)
{
    $event =& DoceboEventManager::newEvent($class, $module, $section, $priority, $description);
    $event->deleteOldProperty();
    if (is_array($recipients["to"]) && is_array($recipients["cc"]) && is_array($recipients["bcc"])) {
        $event->setProperty('recipientid', implode(',', $recipients["to"]));
        $event->setProperty('recipientcc', implode(',', $recipients["cc"]));
        $event->setProperty('recipientbcc', implode(',', $recipients["bcc"]));
    } else {
        $event->setProperty('recipientid', implode(',', $recipients));
    }
    $event->setProperty('subject', addslashes($msg_composer->getSubject('email', getLanguage())));
    $event->setProperty('body', addslashes($msg_composer->getBody('email', getLanguage())));
    $msg_composer->prepare_serialize();
    // __sleep is preferred but i preferr this method
    $event->setProperty('MessageComposer', addslashes(rawurlencode(serialize($msg_composer))));
    $event->setProperty('force_email_send', $force_email_send === false ? 'false' : 'true');
    DoceboEventManager::dispatch($event);
}
Example #2
0
 function extendedParsing($arrayState, $arrayExpand, $arrayCompress)
 {
     if (isset($arrayState['editpersonsave'])) {
         $idst = $_POST['idst'];
         $userid = $_POST['userid'];
         $firstname = $_POST['firstname'];
         $lastname = $_POST['lastname'];
         $pass = $_POST['pass'];
         $userlevel = $_POST['userlevel'];
         $olduserlevel = $_POST['olduserlevel'];
         if ($pass === '') {
             $pass = FALSE;
         }
         $email = $_POST['email'];
         if ($idst !== '') {
             //-extra field-----------------------------------------------
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             $fields = new FieldList();
             //$re_filled = $fields->isFilledFieldsForUser($idst);
             if ($userid != '') {
                 $info = $this->aclManager->getUser($idst, false);
                 $this->aclManager->updateUser($idst, $userid, $firstname, $lastname, $pass, $email, FALSE, FALSE);
                 //-extra field-----------------------------------------------
                 $fields->storeFieldsForUser($idst);
                 //-----------------------------------------------------------
                 // remove from old group level
                 $this->aclManager->removeFromGroup($olduserlevel, $idst);
                 // add to group level
                 $this->aclManager->addToGroup($userlevel, $idst);
                 if ($this->aclManager->absoluteId($userid) != $info[ACL_INFO_USERID] || $this->aclManager->encrypt($pass) != $info[ACL_INFO_PASS]) {
                     require_once _base_ . '/lib/lib.eventmanager.php';
                     $pl_man = PlatformManager::createInstance();
                     $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                     // message to user that is odified
                     $msg_composer = new EventMessageComposer();
                     $msg_composer->setSubjectLangText('email', '_MODIFIED_USER_SBJ', false);
                     $msg_composer->setBodyLangText('email', '_MODIFIED_USER_TEXT', $array_subst);
                     if ($pass != '') {
                         $msg_composer->setBodyLangText('email', '_PASSWORD_CHANGED', array('[password]' => $pass));
                     }
                     $msg_composer->setBodyLangText('sms', '_MODIFIED_USER_TEXT_SMS', $array_subst);
                     if ($pass != '') {
                         $msg_composer->setBodyLangText('sms', '_PASSWORD_CHANGED_SMS', array('[password]' => $pass));
                     }
                     createNewAlert('UserMod', 'directory', 'edit', '1', 'User ' . $userid . ' was modified', array($userid), $msg_composer);
                 }
                 $GLOBALS['page']->add(getResultUi($this->lang->def('_OPERATION_SUCCESSFUL')));
             } else {
                 $this->op = 'reedit_person';
                 //$GLOBALS['page']->add( getErrorUi( implode(',', $re_filled) ), 'content');
             }
         } else {
             if (isset($_POST['arr_idst_groups'])) {
                 $arr_idst_groups = unserialize(urldecode($_POST['arr_idst_groups']));
                 $acl =& Docebo::user()->getACL();
                 $arr_idst_all = $acl->getArrSTGroupsST($arr_idst_groups);
             } else {
                 $arr_idst_groups = FALSE;
                 $arr_idst_all = FALSE;
             }
             //-verify that userid is not already used
             if ($this->aclManager->getUserST($userid) !== FALSE) {
                 $GLOBALS['page']->add(getErrorUi($this->lang->def('_USERID_DUPLICATE')));
                 $_POST['userid'] = '';
                 $this->op = 'reedit_person';
             } else {
                 //-verify mandatory extra field--------------------------------
                 require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
                 $fields = new FieldList();
                 //$re_filled = $fields->isFilledFieldsForUser(0, $arr_idst_all);
                 if ($arr_idst_groups != FALSE && $userid != '') {
                     $idst = false;
                     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
                         $limit_insert = Docebo::user()->preference->getAdminPreference('admin_rules.limit_user_insert');
                         $max_insert = Docebo::user()->preference->getAdminPreference('admin_rules.max_user_insert');
                         $direct_insert = Docebo::user()->preference->getAdminPreference('admin_rules.direct_user_insert');
                         if ($limit_insert == 'off' || $limit_insert == 'on' && $max_insert > 0) {
                             if ($direct_insert == 'on') {
                                 Docebo::user()->preference->setPreference('admin_rules.max_user_insert', $max_insert - 1);
                                 $idst = $this->aclManager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '');
                                 require_once _base_ . '/lib/lib.preference.php';
                                 $preference = new UserPreferences($idst);
                                 $preference->savePreferences($_POST, 'ui.');
                                 require_once _base_ . "/lib/lib.eventmanager.php";
                                 $pl_man =& PlatformManager::createInstance();
                                 $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                                 // message to user that is inserted
                                 $msg_composer = new EventMessageComposer();
                                 $msg_composer->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
                                 $msg_composer->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
                                 $msg_composer->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
                                 createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' created', array($userid), $msg_composer);
                                 $GLOBALS['page']->add(getResultUi($this->lang->def('_INSERTED_NEW_USER')));
                             } else {
                                 $acl = Docebo::user()->getAcl();
                                 $idst = $this->aclManager->registerTempUser($userid, $firstname, $lastname, $pass, $email, 0, getLogUserId());
                                 require_once _base_ . "/lib/lib.eventmanager.php";
                                 $pl_man =& PlatformManager::createInstance();
                                 $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                                 // message to user that is waiting
                                 $msg_composer = new EventMessageComposer();
                                 $msg_composer->setSubjectLangText('email', '_WAITING_USER_SBJ', false);
                                 $msg_composer->setBodyLangText('email', '_WAITING_USER_TEXT', $array_subst);
                                 $msg_composer->setBodyLangText('sms', '_WAITING_USER_TEXT_SMS', $array_subst);
                                 // send message to the user subscribed
                                 createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' was modified', array($userid), $msg_composer);
                                 // set as recipients all who can approve a waiting user
                                 $msg_c_approve = new EventMessageComposer();
                                 $msg_c_approve->setSubjectLangText('email', '_TO_APPROVE_USER_SBJ', false);
                                 $msg_c_approve->setBodyLangText('email', '_TO_APPROVE_USER_TEXT', array('[url]' => Get::sett('url')));
                                 $msg_c_approve->setBodyLangText('sms', '_TO_APPROVE_USER_TEXT_SMS', array('[url]' => Get::sett('url')));
                                 $idst_approve = $acl->getRoleST('/framework/admin/directory/approve_waiting_user');
                                 $recipients = $this->aclManager->getAllRoleMembers($idst_approve);
                                 createNewAlert('UserNewModerated', 'directory', 'edit', '1', 'User ' . $userid . ' to moderate', $recipients, $msg_c_approve);
                                 $GLOBALS['page']->add(getResultUi($this->lang->def('_INSERTED_WAIT_FOR_ADMIN')));
                             }
                         }
                     } else {
                         $idst = $this->aclManager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '');
                         require_once _base_ . '/lib/lib.preference.php';
                         $preference = new UserPreferences($idst);
                         $preference->savePreferences($_POST, 'ui.');
                         require_once _base_ . "/lib/lib.eventmanager.php";
                         $pl_man =& PlatformManager::createInstance();
                         $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $userid, '[password]' => $pass);
                         // message to user that is inserted
                         $msg_composer = new EventMessageComposer();
                         $msg_composer->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
                         $msg_composer->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
                         $msg_composer->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
                         createNewAlert('UserNew', 'directory', 'edit', '1', 'User ' . $userid . ' created', array($idst), $msg_composer);
                     }
                     if ($idst !== false) {
                         foreach ($arr_idst_groups as $idst_group) {
                             $this->aclManager->addToGroup($idst_group, $idst);
                         }
                         // add to group level
                         $this->aclManager->addToGroup($userlevel, $idst);
                         //-save extra field------------------------------------------
                         $fields->storeFieldsForUser($idst, $arr_idst_all);
                         //-----------------------------------------------------------
                     }
                 } else {
                     $this->op = 'reedit_person';
                     //$GLOBALS['page']->add(getErrorUi(implode('<br/>', $re_filled)), 'content');
                 }
             }
         }
     } elseif (isset($arrayState['deleteperson'])) {
         $idst = $_POST['idst'];
         if ($idst !== '') {
             require_once _base_ . "/lib/lib.eventmanager.php";
             $u_info = $this->aclManager->getUser($idst, false);
             $userid = $u_info[ACL_INFO_USERID];
             $pl_man =& PlatformManager::createInstance();
             $acl_man =& Docebo::user()->getAclManager();
             $array_subst = array('[url]' => Get::sett('url', ''), '[userid]' => $acl_man->relativeId($userid));
             // message to user that is inserted
             $msg_composer = new EventMessageComposer();
             $msg_composer->setSubjectLangText('email', '_DELETED_USER_SBJ', false);
             $msg_composer->setBodyLangText('email', '_DELETED_USER_TEXT', $array_subst);
             $msg_composer->setBodyLangText('sms', '_DELETED_USER_TEXT_SMS', $array_subst);
             /*
             				createNewAlert(	'UserDel', 'directory', 'edit', '1', 'User '.$userid.' deleted',
             							array($idst), $msg_composer );*/
             $event =& DoceboEventManager::newEvent('UserDel', 'directory', 'edit', '1', 'User ' . addslashes($userid) . ' deleted');
             $event->setProperty('recipientid', implode(',', array($idst)));
             $event->setProperty('subject', $msg_composer->getSubject('email', getLanguage()));
             $event->setProperty('body', $msg_composer->getBody('email', getLanguage()));
             $msg_composer->prepare_serialize();
             $event->setProperty('MessageComposer', addslashes(rawurlencode(serialize($msg_composer))));
             $event->setProperty('userdeleted', $idst);
             DoceboEventManager::dispatch($event);
             $this->aclManager->deleteUser($idst);
             $GLOBALS['page']->add(getResultUi($this->lang->def('_OPERATION_SUCCESSFUL')));
         }
     }
     if (!isset($arrayState[$this->id])) {
         return;
     }
     foreach ($arrayState[$this->id] as $key => $action) {
         if ($key == 'save_newfolder') {
             $array_lang = Docebo::langManager()->getAllLangCode();
             $mand_lang = getLanguage();
             if (!isset($action[$mand_lang])) {
                 $this->op = 'newfolder';
             } else {
                 $folderName = array();
                 foreach ($array_lang as $langItem) {
                     $folderName[$langItem] = $arrayState[$this->id]['new_folder'][$langItem];
                 }
                 $this->tdb->addFolderByIdTranslation($this->selectedFolder, $folderName);
                 $this->refresh = TRUE;
             }
         } elseif ($key == 'save_renamefolder') {
             $array_lang = Docebo::langManager()->getAllLangCode();
             if ($this->getSelectedFolderId() == '0') {
                 $mand_lang = 'root';
             } else {
                 $mand_lang = getLanguage();
             }
             if (!isset($action[$mand_lang]) || $action[$mand_lang] == '') {
                 $this->op = 'renamefolder';
             } else {
                 $folder_id = $this->getSelectedFolderId();
                 $acl =& Docebo::user()->getACL();
                 //-extra field check mandatory -----------------------------
                 require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
                 $fields = new FieldList();
                 $fields->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
                 $fields->setFieldEntryTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDENTRYTABLE);
                 $folder_id = $this->getSelectedFolderId();
                 $folder =& $this->tdb->getFolderById($folder_id);
                 $ancestor = $this->tdb->getAllParentId($folder, $this->tdb);
                 array_push($ancestor, $folder_id);
                 //$filled = $fields->isFilledFieldsForUser($folder_id, $ancestor, FALSE );
                 //----------------------------------------------------------
                 //if( $filled === true ) {
                 $folderName = array();
                 if ($this->getSelectedFolderId() == '0') {
                     // is root
                     $folderName = $arrayState[$this->id]['rename_folder']['root'];
                     $query_root_name = "\r\n\t\t\t\t\t\t\tUPDATE " . $GLOBALS['prefix_fw'] . "_setting \r\n\t\t\t\t\t\t\tSET param_value = '" . $folderName . "'\r\n\t\t\t\t\t\t\tWHERE param_name = 'title_organigram_chart'";
                     sql_query($query_root_name);
                 } else {
                     foreach ($array_lang as $langItem) {
                         $folderName[$langItem] = $arrayState[$this->id]['rename_folder'][$langItem];
                     }
                     $this->tdb->updateFolderByIdTranslation($this->selectedFolder, $folderName);
                 }
                 //-extra field store --------------------------------------
                 $folder_idst = $this->tdb->getGroupST($folder_id);
                 $fl = new FieldList();
                 $fl->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
                 $fl->setFieldEntryTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDENTRYTABLE);
                 $arr_groups_filterd = $acl->getSTGroupsST($folder_idst, FILTER_FOLD);
                 $fl->storeFieldsForUser($folder_id, $ancestor, FALSE);
                 //----------------------------------------------------------
                 $this->refresh = TRUE;
                 if ($this->getSelectedFolderId() == '0') {
                     Util::jump_to('index.php?modname=directory&op=org_chart');
                 }
                 /*} else {
                 			
                 			$this->op = 'renamefolder';
                 			$GLOBALS['page']->add( getErrorUi(implode('<br/>', $filled)), 'content' );
                 		}*/
             }
         } elseif ($key == 'next_formfield1') {
             $this->op = 'folder_field2';
         } elseif ($key == 'save_formfield') {
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             if (isset($arrayState[$this->id]['field_set'])) {
                 $arr_fields = $arrayState[$this->id]['field_set'];
             } else {
                 $arr_fields = array();
             }
             if (isset($arrayState[$this->id]['field_mandatory'])) {
                 $arr_fields_mandatory = $arrayState[$this->id]['field_mandatory'];
             } else {
                 $arr_fields_mandatory = array();
             }
             $fl = new FieldList();
             $fl->setGroupFieldsTable($GLOBALS['prefix_fw'] . ORGCHAR_FIELDTABLE);
             $arr_all_fields = $fl->getAllFields();
             $id_folder = $this->getSelectedFolderId();
             // remove all fields
             foreach ($arr_all_fields as $id_field => $field) {
                 $fl->removeFieldFromGroup($id_field, $id_folder);
             }
             // add selected fields
             foreach ($arr_fields as $id_field => $dummy_val) {
                 $fl->addFieldToGroup($id_field, $id_folder, isset($arr_fields_mandatory[$id_field]) ? $arr_fields_mandatory[$id_field] : 'false');
             }
         } elseif ($key == 'next1_assignfield') {
             $this->op = 'assign2_field';
         } elseif ($key == 'next2_assignfield') {
             $this->op = 'assign3_field';
         } elseif ($key == 'save_assignfield') {
             $arr_fields = $arrayState[$this->id]['field_set'];
             $arr_fields_mandatory = isset($arrayState[$this->id]['field_mandatory']) ? $arrayState[$this->id]['field_mandatory'] : array();
             $arr_fields_useraccess = isset($arrayState[$this->id]['field_useraccess']) ? $arrayState[$this->id]['field_useraccess'] : array();
             require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
             $fl = new FieldList();
             foreach ($arr_fields as $id_filed => $status) {
                 switch ($status) {
                     case ORG_CHART_FIELD_NO:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()));
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()));
                         break;
                     case ORG_CHART_FIELD_NORMAL:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()));
                         $fl->addFieldToGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()), isset($arr_fields_mandatory[$id_filed]) ? $arr_fields_mandatory[$id_filed] : 'false', isset($arr_fields_useraccess[$id_filed]) ? $arr_fields_useraccess[$id_filed] : 'readonly');
                         break;
                     case ORG_CHART_FIELD_DESCEND:
                         $fl->removeFieldFromGroup($id_filed, $this->tdb->getGroupST($this->getSelectedFolderId()));
                         $fl->addFieldToGroup($id_filed, $this->tdb->getGroupDescendantsST($this->getSelectedFolderId()), isset($arr_fields_mandatory[$id_filed]) ? $arr_fields_mandatory[$id_filed] : 'false', isset($arr_fields_useraccess[$id_filed]) ? $arr_fields_useraccess[$id_filed] : 'readonly');
                         break;
                 }
             }
         } elseif ($key == $this->_getOpFolderField()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'folder_field';
         } elseif ($key == $this->_getOpImportUsers()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'import_users';
         } elseif ($key == 'next1_importusers') {
             $this->op = 'import_users2';
         } elseif ($key == 'next2_importusers') {
             $this->op = 'import_users3';
         } elseif ($key == $this->_getOpAssignField()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'assign_field';
         } elseif ($key == $this->_getOpAssignUser()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'addtotree';
         } elseif ($key == $this->_getOpCreateUser()) {
             if (is_array($action)) {
                 $this->selectedFolder = key($action);
             }
             $this->op = 'create_user';
         } elseif ($key == $this->_getOpWaitingUser()) {
             $this->op = 'waiting_user';
         }
     }
     return;
     $arrayExpand = $arrayExpand;
     $arrayCompress = $arrayCompress;
 }