/** * @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 _maskTemplateManager() { require_once _base_ . '/lib/lib.form.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.field.php'; require_once _base_ . '/lib/lib.table.php'; $lang =& DoceboLanguage::createInstance('configuration', 'framework'); $field_man = new FieldList(); $html = ''; if (isset($_POST['save_and_refresh'])) { if (!sql_query("\r\n\t\t\tUPDATE " . $this->table . "\r\n\t\t\tSET param_value = '" . $_POST['templ_use_field'] . "'\r\n\t\t\tWHERE pack = 'main' AND param_name = 'templ_use_field'")) { $html .= getErrorUi('_ERROR_WHILE_SAVING_NEW_FIELD'); } else { setTemplate($_POST['templ_use_field']); } } $drop_field = array(); $drop_field = $field_man->getFlatAllFields(false, 'dropdown'); $drop_field[0] = $lang->def('_NO'); $html .= Form::getDropdown($lang->def('_TEMPL_USE_FIELD'), 'templ_use_field', 'templ_use_field', $drop_field, Get::sett('templ_use_field')); $html .= Form::getButton('save_and_refresh', 'save_and_refresh', $lang->def('_SAVE_AND_REFRESH')); if (Get::sett('templ_use_field') != 0) { $field_obj =& $field_man->getFieldInstance(Get::sett('templ_use_field')); if ($field_obj === NULL) { return $html . getErrorUi('_ERROR_WITH_THIS_FIELD'); } $assignement = array(); $query_template_assigned = "\r\n\t\t\tSELECT ref_id, template_code\r\n\t\t\tFROM " . $GLOBALS['prefix_fw'] . "_field_template\r\n\t\t\tWHERE id_common = '" . Get::sett('templ_use_field') . "'"; $re_templ_assigned = sql_query($query_template_assigned); while (list($ref_id, $template_code) = sql_fetch_row($re_templ_assigned)) { $assignement[$ref_id] = $template_code; } $son_value = $field_obj->getAllSon(); $template_list = getTemplateList(true); $default_template = getDefaultTemplate(); $tb_son = new Table(0, $lang->def('_ASSIGN_DROPDOWN_VALUE_TEMPLATE'), $lang->def('_ASSIGN_DROPDOWN_VALUE_TEMPLATE_SUMMARY')); $cont_h = array($lang->def('_VALUE'), $lang->def('_TEMPLATE_VALUE')); $type_h = array('', ''); $tb_son->setColsStyle($type_h); $tb_son->addHead($cont_h); while (list($id_son, $drop_son_name) = each($son_value)) { $cont = array('<label for="template_selected_' . $id_son . '">' . $drop_son_name . '</label>', Form::getInputDropdown('dropdown', 'template_selected_' . $id_son, 'template_selected[' . $id_son . ']', $template_list, isset($assignement[$id_son]) && isset($template_list[$assignement[$id_son]]) ? $assignement[$id_son] : $default_template, '')); $tb_son->addBody($cont); } $html .= $tb_son->getTable(); } return $html; }
/** * retrive the value of the extra field for the user that is classiied as contact without checking the access list */ function getUserContactNoRestriction($id_user) { require_once $GLOBALS['where_framework'] . '/lib/lib.field.php'; $field_man = new FieldList(); $field_founded = $field_man->getFieldsAndValueFromUser($id_user, false, false, array('contact')); $field = array(); foreach ($field_founded as $id => $arr_value) { $ob =& $field_man->getFieldInstance($id, $arr_value[5], $arr_value[6]); $field[$id] = array('name' => $arr_value[0], 'value' => $arr_value[1], 'href' => $ob->getIMBrowserHref($id_user, $arr_value[1]), 'image' => $ob->getIMBrowserImageSrc($id_user, $arr_value[1]), 'head' => $ob->getIMBrowserHead($id_user, $arr_value[1]), 'field_type' => $arr_value[4]); } return $field; }
function getUsers($param = false) { //retrieve all users matching given conditions $output = array(); $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $a_obj = new DoceboACLManager(); $fman = new FieldList(); $user_to_check = Get::req('user', DOTY_INT, false); $f_arr = $param ? $param : urldecode(stripslashes(Get::req($this->id . "_input", DOTY_STRING, false))); $filter = is_string($f_arr) ? $json->decode(stripslashes($f_arr)) : $f_arr; $exclusive = $filter['exclusive']; $conds = $filter['filters']; //return a void array if no conditions specified if (count($conds) <= 0) { return array(); } //compose nested query // base query /Anonymous $base_query = "SELECT idst, userid " . " FROM %adm_user "; $std_condition = array(); $in_conditions = array(); $other_conditions = array(); foreach ($conds as $cond) { $id_field = $cond['id_field']; $params = $json->decode($cond['value']); if ($params == null) { $params = $cond['value']; } $res = $exclusive; list($id_type, $id) = explode('_', $id_field); switch ($id_type) { case _STANDARD_FIELDS_PREFIX: require_once _adm_ . '/modules/field/class.field.php'; require_once _adm_ . '/modules/field/class.date.php'; switch ($id) { case 0: //userid $temp = " userid "; switch ($params['cond']) { case 2: $temp .= " = '" . $a_obj->absoluteId($params['value']) . "' "; break; //equals //equals case 0: $temp .= " LIKE '%" . $params['value'] . "%' "; break; //contains //contains case 3: $temp .= " <> '" . $a_obj->absoluteId($params['value']) . "' "; break; //not equal //not equal case 1: $temp .= " NOT LIKE '%" . $params['value'] . "%' "; break; //does not contain //does not contain case 4: $temp .= " LIKE '" . $a_obj->absoluteId($params['value']) . "%' "; break; //starts with //starts with case 5: $temp .= " LIKE '%" . $params['value'] . "' "; break; //ends with //ends with default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; case 1: //firstname $temp = " firstname "; switch ($params['cond']) { case 2: $temp .= " = '" . $params['value'] . "' "; break; //equals //equals case 0: $temp .= " LIKE '%" . $params['value'] . "%' "; break; //contains //contains case 3: $temp .= " <> '" . $params['value'] . "' "; break; //not equal //not equal case 1: $temp .= " NOT LIKE '%" . $params['value'] . "%' "; break; //does not contain //does not contain case 4: $temp .= " LIKE '" . $params['value'] . "%' "; break; //starts with //starts with case 5: $temp .= " LIKE '%" . $params['value'] . "' "; break; //ends with //ends with default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; case 2: //lastname $temp = " lastname "; switch ($params['cond']) { case 2: $temp .= " = '" . $params['value'] . "' "; break; //equals //equals case 0: $temp .= " LIKE '%" . $params['value'] . "%' "; break; //contains //contains case 3: $temp .= " <> '" . $params['value'] . "' "; break; //not equal //not equal case 1: $temp .= " NOT LIKE '%" . $params['value'] . "%' "; break; //does not contain //does not contain case 4: $temp .= " LIKE '" . $params['value'] . "%' "; break; //starts with //starts with case 5: $temp .= " LIKE '%" . $params['value'] . "' "; break; //ends with //ends with default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; case 3: //email $temp = " email "; switch ($params['cond']) { case 2: $temp .= " = '" . $params['value'] . "' "; break; //equals //equals case 0: $temp .= " LIKE '%" . $params['value'] . "%' "; break; //contains //contains case 3: $temp .= " <> '" . $params['value'] . "' "; break; //not equal //not equal case 1: $temp .= " NOT LIKE '%" . $params['value'] . "%' "; break; //does not contain //does not contain case 4: $temp .= " LIKE '" . $params['value'] . "%' "; break; //starts with //starts with case 5: $temp .= " LIKE '%" . $params['value'] . "' "; break; //ends with //ends with default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; case 4: //register date $date = substr(Format::dateDb($params['value'], 'date'), 0, 10); $temp = " register_date "; switch ($params['cond']) { case 0: $temp .= " < '" . $date . " 00:00:00' "; break; //< //< case 1: $temp .= " <= '" . $date . " 23:59:59' "; break; //<= //<= case 2: $temp = " ( register_date >= '" . $date . " 00:00:00' AND register_date <= '" . $date . " 23:59:59' ) "; break; //= //= case 3: $temp .= " >= '" . $date . " 00:00:00' "; break; //>= //>= case 4: $temp .= " > '" . $date . " 23:59:59' "; break; //> //> default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; case 5: //lastenter $date = substr(Format::dateDb($params['value'], 'date'), 0, 10); $temp = " lastenter "; switch ($params['cond']) { case 0: $temp .= " < '" . $date . " 00:00:00' "; break; //< //< case 1: $temp .= " <= '" . $date . " 23:59:59' "; break; //<= //<= case 2: $temp = " ( lastenter >= '" . $date . " 00:00:00' AND lastenter <= '" . $date . " 23:59:59' ) "; break; //= //= case 3: $temp .= " >= '" . $date . " 00:00:00' "; break; //>= //>= case 4: $temp .= " > '" . $date . " 23:59:59' "; break; //> //> default: $temp .= " NOT LIKE '%' "; //unexistent } $std_condition[] = $temp; break; default: } break; // filter on a custom field // filter on a custom field case _CUSTOM_FIELDS_PREFIX: $fobj = $fman->getFieldInstance($id); $in_conditions[] = $fobj->getFieldQuery($params); break; // other special field // other special field case _OTHER_FIELDS_PREFIX: $ofobj = new OtherFieldsTypes(); $other_conditions[] = $ofobj->getFieldQuery($id, $params); break; default: } //end switch } //end foreach if ($exclusive) { $query = $base_query . ' WHERE 1 ' . (!empty($std_condition) ? " AND " . implode(" AND ", $std_condition) : '') . (!empty($in_conditions) ? ' AND idst IN ( ' . implode(" ) AND idst IN ( ", $in_conditions) . ' ) ' : '') . (!empty($other_conditions) ? ' AND idst IN ( ' . implode(" ) AND idst IN ( ", $other_conditions) . ' ) ' : ''); } else { $query = $base_query . ' WHERE 0 ' . (!empty($std_condition) ? ' OR ( ' . implode(" ) OR idst IN ( ", $std_condition) . ' ) ' : '') . (!empty($in_conditions) ? ' OR idst IN ( ' . implode(" ) OR idst IN ( ", $in_conditions) . ' ) ' : '') . (!empty($other_conditions) ? ' OR idst IN ( ' . implode(" ) OR idst IN ( ", $other_conditions) . ' ) ' : ''); } //produce output $output = array(); $re = $this->db->query($query); while ($rw = $this->db->fetch_assoc($re)) { if ($rw['userid'] != '/Anonymous') { $output[] = $rw['idst']; } } return $output; }