function checkUser($user_to_check, $param = false)
 {
     $output = false;
     $_testvar = '';
     $f_arr = $param ? $param : Get::req($this->id . "_input", DOTY_MIXED, false);
     if (!$user_to_check) {
         return $output;
     }
     if (!$f_arr) {
         return $output;
     }
     $a_obj = Docebo::user()->getAclManager();
     $fman = new FieldList();
     $filter = $this->json->decode(stripslashes($f_arr));
     $user_data_std = $a_obj->getUser($user_to_check, false);
     $user_data_extra = $fman->getUserFieldEntryData($user_to_check, false);
     $exclusive = $filter['exclusive'];
     $conds = $filter['filters'];
     if (count($conds) <= 0) {
         return true;
     }
     //if no conditions, return true anyway
     $output = $exclusive;
     foreach ($conds as $cond) {
         $id_field = $cond['id_field'];
         $params = $this->json->decode($cond['value']);
         if ($params == null) {
             $params = $cond['value'];
         }
         $res = $exclusive;
         list($id_type, $id) = explode('_', $id_field);
         switch ($id_type) {
             // stadard core_user fields
             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
                         $user_data_std[ACL_INFO_USERID] = $a_obj->relativeId($user_data_std[ACL_INFO_USERID]);
                         $res = Field::checkUserField($user_data_std[ACL_INFO_USERID], $params);
                         break;
                     case 1:
                         //firstname
                         $res = Field::checkUserField($user_data_std[ACL_INFO_FIRSTNAME], $params);
                         break;
                     case 2:
                         //lastname
                         $res = Field::checkUserField($user_data_std[ACL_INFO_LASTNAME], $params);
                         break;
                     case 3:
                         //email
                         $res = Field::checkUserField($user_data_std[ACL_INFO_EMAIL], $params);
                         break;
                     case 4:
                         //register date
                         $res = Field_Date::checkUserField($user_data_std[ACL_INFO_REGISTER_DATE], $params);
                         break;
                     case 5:
                         //lastenter
                         $res = Field_Date::checkUserField($user_data_std[ACL_INFO_LASTENTER], $params);
                         break;
                     default:
                         $res = false;
                 }
                 break;
                 // custom fields -----------------------------------
             // custom fields -----------------------------------
             case _CUSTOM_FIELDS_PREFIX:
                 //first check if the user own this extra field
                 if (isset($user_data_extra[$id])) {
                     $fobj = $fman->getFieldInstance($id);
                     $res = $fobj->checkUserField($user_data_extra[$id], $params);
                     //check if the field value match the condition
                 } else {
                     $res = false;
                 }
                 break;
                 // other fields -------------------------------------
             // other fields -------------------------------------
             case _OTHER_FIELDS_PREFIX:
                 $ofobj = new OtherFieldTypes();
                 $res = $ofobj->checkUserField($id, $user_to_check, $params);
                 break;
             default:
                 $res = false;
         }
         if ($exclusive) {
             //AND of conditions
             if (!$res) {
                 $output = false;
                 break;
             }
         } else {
             //OR of conditions
             if ($res) {
                 $output = true;
                 break;
             }
         }
     }
     return $output;
 }
Example #2
0
 /**
  * display the field for filters
  *
  * @param	string	$field_id		the id of the field used for id/name
  * @param 	mixed 	$value 			(optional) the value to put in the field
  *										retrieved from $_POST if not given
  * @param	string	$label			(optional) the label to use if not given the
  *									value will be retrieved from custom field
  *									$id_field
  * @param	string	$field_prefix 	(optional) the prefix to give to
  *									the field id/name
  * @param 	string 	$other_after 	optional html code added after the input element
  * @param	string 	$other_before 	optional html code added before the label element
  * @param   mixed 	$field_special	(optional) not used
  *
  * @return string 	of field xhtml code
  *
  * @access public
  */
 function play_filter($id_field, $value = FALSE, $label = FALSE, $field_prefix = FALSE, $other_after = '', $other_before = '', $field_special = FALSE)
 {
     require_once _base_ . '/lib/lib.form.php';
     if ($value === FALSE) {
         $value = Field::getFieldValue_Filter($_POST, $id_field, $field_prefix, '');
     }
     if ($label === FALSE) {
         $re_field = sql_query("\r\n\t\t\tSELECT translation\r\n\t\t\tFROM " . Field::_getMainTable() . "\r\n\t\t\tWHERE id_common = '" . (int) $id_field . "' AND type_field = '" . Field_Date::getFieldType() . "'");
         list($label) = sql_fetch_row($re_field);
     }
     return Form::getDatefield($label, Field::getFieldId_Filter($id_field, $field_prefix), Field::getFieldName_Filter($id_field, $field_prefix), $value, false, false, $label, $other_after, $other_before);
 }