/**
  * @param array $predefined_data
  * @param array $custom_data
  * @param integer $id user id; if 0 a new user will be created
  * @param boolean $dropdown_id if true will take dropdown values as id;
  *                             else will search the id starting from the value.
  */
 function saveFields($predefined_data, $custom_data, $id = 0, $dropdown_id = TRUE)
 {
     require_once $GLOBALS["where_crm"] . "/modules/company/lib.company.php";
     // TODO: at this moment the function works only for user creation;
     // does not update the user if it already exists
     $acl =& Docebo::user()->getACL();
     $acl_manager =& Docebo::user()->getAclManager();
     $data = array();
     $userid = $predefined_data["userid"];
     $firstname = $predefined_data["firstname"];
     $lastname = $predefined_data["lastname"];
     $pass = $predefined_data["pass"];
     $email = $predefined_data["email"];
     if (!empty($userid)) {
         $idst = $acl_manager->registerUser($userid, $firstname, $lastname, $pass, $email, '', '');
     } else {
         $idst = FALSE;
     }
     if ($idst !== false) {
         //  -- Add user to registered users group if not importing into root ---
         $idst_oc = $acl_manager->getGroup(false, '/oc_0');
         $idst_oc = $idst_oc[ACL_INFO_IDST];
         $idst_ocd = $acl_manager->getGroup(false, '/ocd_0');
         $idst_ocd = $idst_ocd[ACL_INFO_IDST];
         $acl_manager->addToGroup($idst_oc, $idst);
         $acl_manager->addToGroup($idst_ocd, $idst);
         //  -------------------------------------------------------------------|
         // add to group level
         $userlevel = $acl_manager->getGroupST(ADMIN_GROUP_USER);
         $acl_manager->addToGroup($userlevel, $idst);
         // -- Custom fields ----------------------------------------------------
         require_once $GLOBALS["where_framework"] . "/lib/lib.field.php";
         $res = array();
         $fl = new FieldList();
         $custom_fields = array_keys($this->getCustomFields(FALSE));
         $field_info_arr = $fl->getFieldsFromIdst($custom_fields);
         foreach ($custom_fields as $field_id) {
             // store direct
             if (isset($custom_data[$field_id])) {
                 $field_obj =& $fl->getFieldInstance($field_id);
                 //					$field_obj->setFieldEntryTable($company_entry_table);
                 $field_obj->storeDirect($idst, $custom_data[$field_id], $dropdown_id, FALSE, TRUE);
             }
         }
     }
     return $idst;
 }
 function connect()
 {
     require_once _base_ . '/lib/lib.userselector.php';
     require_once _adm_ . '/lib/lib.field.php';
     $aclManager = Docebo::user()->getACLManager();
     $this->directory = new UserSelector();
     $this->groupFilter_idst = $aclManager->getGroupST($this->groupFilter);
     // load language for fields names
     $lang_dir = DoceboLanguage::createInstance('admin_directory', 'framework');
     $fl = new FieldList();
     $this->fl = $fl;
     // root and root descendant
     $tmp = $aclManager->getGroup(false, '/oc_0');
     $arr_idst[] = $tmp[0];
     $this->tree_oc = $tmp[0];
     $tmp = $aclManager->getGroup(false, '/ocd_0');
     $arr_idst[] = $tmp[0];
     $this->tree_ocd = $tmp[0];
     // tree folder selected
     if ($this->tree != 0) {
         $arr_groupid = $aclManager->getGroupsId($arr_idst);
         foreach ($arr_groupid as $key => $val) {
             $arr_groupid[$key] = substr_replace($val, '/ocd', 0, 3);
         }
         $arr_result = $aclManager->getArrGroupST($arr_groupid);
         list($this->tree_desc) = array_values($arr_result);
         $arr_idst[] = $this->tree;
         $arr_idst[] = $this->tree_desc;
     }
     $arr_fields = $fl->getFieldsFromIdst($arr_idst);
     // generating cols descriptor
     $this->cols_descriptor = NULL;
     if ($this->dbconn === NULL) {
         $this->dbconn = $GLOBALS['dbConn'];
     }
     $query = "SHOW FIELDS FROM " . $GLOBALS['prefix_fw'] . "_user";
     $rs = sql_query($query, $this->dbconn);
     if ($rs === FALSE) {
         $this->last_error = Lang::t('_OPERATION_FAILURE', 'standard') . $query . ' [' . mysql_error($this->dbconn) . ']';
         return FALSE;
     }
     $this->cols_descriptor = array();
     while ($field_info = mysql_fetch_array($rs)) {
         if (!in_array($field_info['Field'], $this->ignore_cols)) {
             $mandatory = in_array($field_info['Field'], $this->mandatory_cols);
             if (isset($this->default_cols[$field_info['Field']])) {
                 $this->cols_descriptor[] = array(DOCEBOIMPORT_COLNAME => $lang_dir->def('_DIRECTORY_FILTER_' . $field_info['Field']), DOCEBOIMPORT_COLID => $field_info['Field'], DOCEBOIMPORT_COLMANDATORY => $mandatory, DOCEBOIMPORT_DATATYPE => $field_info['Type'], DOCEBOIMPORT_DEFAULT => $this->default_cols[$field_info['Field']]);
             } else {
                 $this->cols_descriptor[] = array(DOCEBOIMPORT_COLNAME => $lang_dir->def('_DIRECTORY_FILTER_' . $field_info['Field']), DOCEBOIMPORT_COLID => $field_info['Field'], DOCEBOIMPORT_COLMANDATORY => $mandatory, DOCEBOIMPORT_DATATYPE => $field_info['Type']);
             }
         }
     }
     mysql_free_result($rs);
     foreach ($arr_fields as $field_id => $field_info) {
         if (in_array($field_info[FIELD_INFO_TYPE], $this->valid_filed_type)) {
             $this->cols_descriptor[] = array(DOCEBOIMPORT_COLNAME => $field_info[FIELD_INFO_TRANSLATION], DOCEBOIMPORT_COLID => $field_id, DOCEBOIMPORT_COLMANDATORY => FALSE, DOCEBOIMPORT_DATATYPE => 'text', DOCEBOIMPORT_DEFAULT => false);
         }
     }
     $this->cols_descriptor[] = array(DOCEBOIMPORT_COLNAME => 'tree_code', DOCEBOIMPORT_COLID => 'tree_code', DOCEBOIMPORT_COLMANDATORY => FALSE, DOCEBOIMPORT_DATATYPE => 'text');
     $this->arr_fields = $arr_fields;
     $this->index = 0;
     $this->eof = true;
     $match = array();
     $this->org_chart_name = array();
     $this->org_chart_group = array();
     $this->user_org_chart = array();
     // cache org_chart group
     $this->org_chart_group = $aclManager->getBasePathGroupST('/oc');
     $query = " SELECT id_dir, translation " . " FROM " . $GLOBALS['prefix_fw'] . "_org_chart" . " WHERE lang_code = '" . getLanguage() . "'";
     $result = sql_query($query);
     while (list($id_dir, $dir_name) = sql_fetch_row($result)) {
         $valid = preg_match('/' . $this->preg_match_folder . '/i', $dir_name, $match);
         if ($valid) {
             $dir_name = $match[1];
         }
         $this->org_chart_name[$dir_name] = $id_dir;
         $idst_group = $this->org_chart_group['/oc_' . $id_dir];
         $query_idstMember = "SELECT idstMember" . " FROM " . $GLOBALS['prefix_fw'] . "_group_members " . " WHERE idst = '" . $idst_group . "'";
         $re = sql_query($query_idstMember);
         while (list($idstMember) = sql_fetch_row($re)) {
             if (!isset($this->user_org_chart[$idstMember])) {
                 $this->user_org_chart[$idstMember] = array();
             }
             $this->user_org_chart[$idstMember][$id_dir] = $id_dir;
         }
     }
     return TRUE;
 }
 function assignfields()
 {
     //check permissions
     if (!$this->permissions['mod_org']) {
         Util::jump_to('index.php?r=' . $this->link . '/show');
     }
     require_once _base_ . '/lib/lib.table.php';
     require_once _adm_ . '/lib/lib.field.php';
     $id_org = Get::req('id_node', DOTY_INT, 0);
     $table = new Table();
     $type_h = array('', 'image', 'image', 'image', 'image', 'image');
     $cont_h = array(Lang::t('_FIELD_NAME', 'organization_chart'), Lang::t('_DIRECTORY_ASSIGNFIELDGROUP', 'admin_directory'), Lang::t('_ORG_CHART_INHERIT', 'organization_chart'), Lang::t('_MANDATORY', 'organization_chart'), Lang::t('_ORG_CHART_FIELD_WRITE', 'organization_chart'), Lang::t('_USER_INHERIT', 'organization_chart'));
     $table->addHead($cont_h, $type_h);
     $fl = new FieldList();
     $acl = Docebo::user()->getACL();
     $acl_man = Docebo::user()->getAclManager();
     $body = "";
     $body .= Form::openForm('assignfieldgroup', 'ajax.adm_server.php?r=' . $this->link . '/assignfields_action');
     $body .= Form::getLineBox(Lang::t('_ORG_CHART_LIST_FIELDS', 'organization_chart') . ': ', $this->model->getOrgPath($id_org));
     $body .= Form::getHidden('idst_group', 'idst_group', $id_org);
     $arr_all_fields = $fl->getAllFields();
     $arr_fields_normal = $fl->getFieldsFromIdst(array($acl_man->getGroupST('oc_' . $id_org)));
     $arr_fields_inherit = $fl->getFieldsFromIdst(array($acl_man->getGroupST('ocd_' . $id_org)));
     //$body .= '<pre>'.print_r($arr_fields_normal, true).print_r($arr_fields_inherit, true).'</pre>';
     foreach ($arr_all_fields as $field) {
         $id_field = $field[FIELD_INFO_ID];
         $def_value = GROUP_FIELD_NO;
         if (isset($arr_fields_normal[$id_field])) {
             $def_value = GROUP_FIELD_NORMAL;
         }
         if (isset($arr_fields_inherit[$id_field])) {
             $def_value = GROUP_FIELD_INHERIT;
         }
         switch ($def_value) {
             case GROUP_FIELD_NORMAL:
                 $is_mandatory = isset($arr_fields_normal[$id_field]) && $arr_fields_normal[$id_field][FIELD_INFO_MANDATORY] == 'true';
                 $is_invisible = isset($arr_fields_normal[$id_field]) && $arr_fields_normal[$id_field][FIELD_INFO_USERACCESS] == 'readwrite';
                 $is_userinherit = isset($arr_fields_normal[$id_field]) && $arr_fields_normal[$id_field][FIELD_INFO_USERINHERIT] == '1';
                 break;
             case GROUP_FIELD_INHERIT:
                 $is_mandatory = isset($arr_fields_inherit[$id_field]) && $arr_fields_inherit[$id_field][FIELD_INFO_MANDATORY] == 'true';
                 $is_invisible = isset($arr_fields_inherit[$id_field]) && $arr_fields_inherit[$id_field][FIELD_INFO_USERACCESS] == 'readwrite';
                 $is_userinherit = isset($arr_fields_inherit[$id_field]) && $arr_fields_inherit[$id_field][FIELD_INFO_USERINHERIT] == '1';
                 break;
             default:
                 $is_mandatory = false;
                 $is_invisible = false;
                 $is_userinherit = false;
         }
         $selected = $def_value != GROUP_FIELD_NO;
         $disabled = 'disabled="disabled"';
         $line = array();
         $line[] = $field[FIELD_INFO_TRANSLATION];
         $line[] = Form::getInputCheckbox('fields_use_' . $id_field, 'fields_use[' . $id_field . ']', 1, $selected, '');
         $line[] = Form::getInputCheckbox('fields_inherit_' . $id_field, 'fields_inherit[' . $id_field . ']', 1, $def_value == GROUP_FIELD_INHERIT, $selected ? '' : $disabled);
         $line[] = Form::getInputCheckbox('fields_mandatory_' . $id_field, 'fields_mandatory[' . $id_field . ']', 1, $is_mandatory, $selected ? '' : $disabled);
         $line[] = Form::getInputCheckbox('fields_invisible_' . $id_field, 'fields_invisible[' . $id_field . ']', 1, $is_invisible, $selected ? '' : $disabled);
         $line[] = Form::getInputCheckbox('fields_userinherit_' . $id_field, 'fields_userinherit[' . $id_field . ']', 1, $is_userinherit, $selected ? '' : $disabled);
         $table->addBody($line);
     }
     $body .= $table->getTable();
     $body .= Form::closeForm();
     $output = array('success' => true, 'header' => Lang::t('_ORGCHART_FOLDER_FIELD_ALT', 'organization_chart'), 'body' => $body);
     //$this->render('assign_fields', $params);
     echo $this->json->encode($output);
 }
Esempio n. 4
0
 /**
  * Assign fields mandatory and user for group
  **/
 function loadAssignField2($groupid)
 {
     $arr_fields = $_POST[DIRECTORY_ID][DIRECTORY_OP_ADDFIELD];
     $idst_group = $_POST[DIRECTORY_ID]['idst_group'];
     require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
     if (isset($_POST[DIRECTORY_ID]['save_assignfield2'])) {
         $fl = new FieldList();
         $arr_fields_mandatory = $_POST[DIRECTORY_ID]['field_mandatory'];
         $arr_fields_useraccess = $_POST[DIRECTORY_ID]['field_useraccess'];
         foreach ($arr_fields as $id_filed => $status) {
             switch ($status) {
                 case GROUP_FIELD_NO:
                     $fl->removeFieldFromGroup($id_filed, $idst_group);
                     break;
                 case GROUP_FIELD_NORMAL:
                     $fl->addFieldToGroup($id_filed, $idst_group, 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;
             }
         }
         Util::jump_to('index.php?modname=directory&op=listgroup');
     } elseif (isset($_POST[DIRECTORY_ID]['cancel_assignfield'])) {
         Util::jump_to('index.php?modname=directory&op=listgroup');
     }
     $fl = new FieldList();
     $arr_all_fields = $fl->getAllFields();
     require_once _base_ . '/lib/lib.form.php';
     $form = new Form();
     $GLOBALS['page']->setWorkingZone('content');
     $GLOBALS['page']->add(getTitleArea($this->lang->def('_GROUPS') . ': ' . $groupid, 'directory_group'));
     $GLOBALS['page']->add('<div class="std_block">');
     $GLOBALS['page']->add($form->openForm('directoryassignfieldgroupmandatory', 'index.php?modname=directory&amp;op=assignfieldmandatory'));
     $GLOBALS['page']->add($form->openElementSpace());
     // print custom fields status
     $arr_fields_normal = $fl->getFieldsFromIdst(array($idst_group));
     $GLOBALS['page']->add($form->getHidden(DIRECTORY_ID . '_idst_group', DIRECTORY_ID . '[idst_group]', $idst_group));
     foreach ($arr_fields as $id_filed => $status) {
         $GLOBALS['page']->add($form->getHidden(DIRECTORY_ID . '_' . $id_filed, DIRECTORY_ID . '[' . DIRECTORY_OP_ADDFIELD . '][' . $id_filed . ']', $status));
     }
     $GLOBALS['page']->add($form->openFormLine() . '<div class="label_effect">&nbsp;</div>' . '<div class="label_head">' . $this->lang->def('_MANDATORY') . '</div>' . '<div class="label_head">' . $this->lang->def('_DIRECTORY_GROUP_FIELD_WRITE') . '</div>' . $form->closeFormLine());
     // checkbox for mandatory and useraccess
     foreach ($arr_fields as $id_filed => $status) {
         if ($status == GROUP_FIELD_NORMAL) {
             $GLOBALS['page']->add($form->openFormLine() . '<div class="label_effect">' . $arr_all_fields[$id_filed][FIELD_INFO_TRANSLATION] . '</div>' . '<input class="label_head" type="checkbox"' . ' id="' . DIRECTORY_ID . '_' . $id_filed . '_mandatory"' . ' name="' . DIRECTORY_ID . '[field_mandatory][' . $id_filed . ']"' . ' value="true"');
             if (isset($arr_fields_normal[$id_filed]) && $arr_fields_normal[$id_filed][FIELD_INFO_MANDATORY] == 'true') {
                 $GLOBALS['page']->add(' checked="checked"');
             }
             $GLOBALS['page']->add(' />');
             $GLOBALS['page']->add($form->getLabel(DIRECTORY_ID . '_' . $id_filed . '_mandatory', $this->lang->def('_MANDATORY'), 'label_bold access-only'));
             // checkbox for useraccess
             $GLOBALS['page']->add('<input class="label_head" type="checkbox"' . ' id="' . DIRECTORY_ID . '_' . $id_filed . '_useraccess"' . ' name="' . DIRECTORY_ID . '[field_useraccess][' . $id_filed . ']"' . ' value="readwrite"');
             if (isset($arr_fields_normal[$id_filed]) && $arr_fields_normal[$id_filed][FIELD_INFO_USERACCESS] == 'readwrite') {
                 $GLOBALS['page']->add(' checked="checked"');
             }
             $GLOBALS['page']->add(' />');
             $GLOBALS['page']->add($form->getLabel(DIRECTORY_ID . '_' . $id_filed . '_useraccess', $this->lang->def('_DIRECTORY_GROUP_FIELD_WRITE'), 'label_bold access-only'));
             $GLOBALS['page']->add($form->closeFormLine());
         }
     }
     $GLOBALS['page']->add($form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('save_assignfield2' . DIRECTORY_ID, DIRECTORY_ID . '[save_assignfield2]', $this->lang->def('_SAVE')) . $form->getButton('cancel_assignfield' . DIRECTORY_ID, DIRECTORY_ID . '[cancel_assignfield]', $this->lang->def('_UNDO')) . $form->closeButtonSpace());
 }
Esempio n. 5
0
 function loadAssignField3()
 {
     $arr_fields = $_POST[$this->id]['field_set'];
     $idst_group = $_POST[$this->id]['idst_group'];
     require_once $GLOBALS['where_framework'] . '/lib/lib.field.php';
     $fl = new FieldList();
     $arr_all_fields = $fl->getAllFields();
     $arr_fields_normal = $fl->getFieldsFromIdst(array($idst_group));
     require_once _base_ . '/lib/lib.form.php';
     $form = new Form();
     $tree = $form->getFormHeader($this->lang->def('_ORG_CHART_LIST_FIELDS'));
     $tree .= $form->openElementSpace();
     $tree .= $this->printState();
     $tree .= $form->getHidden($this->id . '_idst_group', $this->id . '[idst_group]', $idst_group);
     // print custom fields status
     foreach ($arr_fields as $id_filed => $status) {
         $tree .= $form->getHidden($this->id . '_' . $id_filed, $this->id . '[field_set][' . $id_filed . ']', $status);
     }
     // first print already ordered fields
     foreach ($arr_fields_normal as $id_filed => $field) {
     }
     $tree .= $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('next1_assignfield' . $this->id, $this->id . '[save_assignfield]', $this->lang->def('_SAVE')) . $form->getButton($this->_getCancelId(), $this->_getCancelId(), $this->lang->def('_UNDO')) . $form->closeButtonSpace();
     return $tree;
 }