Ejemplo n.º 1
0
 /**
  * processRegistrationCode
  * @param AclManager $acl_man
  * @param UserManagerAdmin $uma
  * @param int $iduser
  * @param string $reg_code
  * @param string $registration_code_type
  * @return array 'success'=>boolean, 'msg'=>string
  */
 public function processRegistrationCode(&$acl_man, &$uma, $iduser, $reg_code, $registration_code_type)
 {
     $res = array('success' => true, 'msg' => '');
     $lang =& DoceboLanguage::createInstance('register', 'lms');
     $code_is_mandatory = Get::sett('mandatory_code', 'off') == 'on';
     if ($reg_code != '') {
         switch ($registration_code_type) {
             case "0":
                 //nothin to do
                 break;
             case "tree_course":
                 //a mixed code, let's cut the tree part and go on with the tree_man and resolve here the course part
                 $course_code = substr(str_replace('-', '', $reg_code), 10, 10);
                 $reg_code = substr(str_replace('-', '', $reg_code), 0, 10);
                 //control course registration
                 require_once _lms_ . '/lib/lib.course.php';
                 $man_course_user = new Man_CourseUser();
                 $jolly_code = Get::sett('jolly_course_code', '');
                 if ($jolly_code == '' || $jolly_code != $course_code) {
                     $course_registration_result = $man_course_user->subscribeUserWithCode($course_code, $iduser);
                     if ($course_registration_result <= 0 && $code_is_mandatory) {
                         $res['success'] = false;
                         $res['msg'] = $lang->def('_INVALID_CODE');
                         return $res;
                     }
                 }
                 //procced with tree_man
             //procced with tree_man
             case "tree_man":
                 // resolving the tree_man
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 if (empty($array_folder) && $code_is_mandatory) {
                     //invalid code
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
             case "code_module":
                 require_once _adm_ . '/lib/lib.code.php';
                 $code_manager = new CodeManager();
                 $valid_code = $code_manager->controlCodeValidity($reg_code);
                 if ($valid_code == 1) {
                     $array_folder = $code_manager->getOrgAssociateWithCode($reg_code);
                     $array_course = $code_manager->getCourseAssociateWithCode($reg_code);
                     $code_manager->setCodeUsed($reg_code, $iduser);
                 } elseif ($valid_code == 0) {
                     //duplicated code entered
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_CODE_ALREDY_USED');
                     return $res;
                 } elseif ($valid_code == -1 && $code_is_mandatory) {
                     //invalid code entered
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
             case "tree_drop":
                 // from the dropdown we will recive the id of the folder
                 $array_folder = array($reg_code => $reg_code);
                 //is a valid id ?
                 break;
             case "custom":
                 //Custom code
                 require_once _adm_ . '/lib/lib.field.php';
                 $field_man = new FieldList();
                 $id_common_filed_1 = $field_man->getFieldIdCommonFromTranslation('Filiale');
                 $id_common_filed_2 = $field_man->getFieldIdCommonFromTranslation('Codice Concessionario');
                 $query = "SELECT `translation`" . " FROM core_field_son" . " WHERE id_common_son = " . (int) $_POST['field_dropdown'][$id_common_filed_1] . " AND lang_code = '" . getLanguage() . "'";
                 list($filed_1_translation) = sql_fetch_row(sql_query($query));
                 $code_part = substr($filed_1_translation, 1, 1);
                 $reg_code = strtoupper($code_part . '_' . $_POST['field_textfield'][$id_common_filed_2]);
                 // resolving the tree_man
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 if (empty($array_folder) && $code_is_mandatory) {
                     //invalid code
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
         }
     } elseif ($code_is_mandatory) {
         //invalid code
         $res['success'] = false;
         $res['msg'] = $lang->def('_INVALID_CODE');
         return $res;
     }
     // now in array_folder we have the associated folder for the users
     if (!empty($array_folder)) {
         //let's find the oc and ocd
         $oc_folders = $uma->getOcFolders($array_folder);
         while (list($id, $ocs) = each($oc_folders)) {
             $acl_man->addToGroup($ocs[0], $iduser);
             $acl_man->addToGroup($ocs[1], $iduser);
         }
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->newRules('_NEW_USER', array($iduser), Lang::get(), current($array_folder));
     }
     // and in array_course the courses
     if (!empty($array_course)) {
         foreach ($array_course as $id_course) {
             require_once _lms_ . '/lib/lib.subscribe.php';
             $subscriber = new CourseSubscribe_Management();
             $subscriber->subscribeUser($iduser, $id_course, '3');
         }
     }
     return $res;
 }