Example #1
0
 /**
  * function to get the goups to which user is associated
  * @param integer $iduser
  * @param array $subordinate_users
  * @param boolean $find_subordinate
  * @return $ret_array
  */
 public function get_groups_by_user($iduser, $subordinate_users = array(), $find_subordinate = false)
 {
     $ret_array = array();
     $users = array();
     if (count($subordinate_users) > 0) {
         $users = array_merge($subordinate_users, array($iduser));
         $users = array_unique($users);
     } else {
         if (true === $find_subordinate) {
             $do_user = new User();
             $subordinate_users = $do_user->get_subordinate_users_by_iduser($iduser);
             if (count($subordinate_users) > 0) {
                 $users = array_merge($subordinate_users, array($iduser));
             } else {
                 $users[] = $iduser;
             }
         } else {
             $users[] = $iduser;
         }
         $users = array_unique($users);
     }
     $this->query("select idgroup from " . $this->table . " where iduser in (" . implode(",", $users) . ")");
     if ($this->getNumRows() > 0) {
         $this->next();
         $ret_array[] = $this->idgroup;
     }
     return $ret_array;
 }
Example #2
0
 /**
  * function to get the userids used for the report data 
  * @param integer $iduser
  * @param boolean $ignore_current_user
  * @return array
  */
 public function get_userids($iduser = 0, $ignore_current_user = true)
 {
     $user_list = array();
     if ((int) $iduser == 0) {
         $iduser = $_SESSION["do_user"]->iduser;
     }
     $do_user = new User();
     $user_list = $do_user->get_subordinate_users_by_iduser($iduser);
     if (false === $ignore_current_user) {
         $user_list[] = $iduser;
     }
     return $user_list;
 }
 /**
  * function to generate the where condition for the user.
  * While displaying data in the list view data may appear from lower level users in the hierarchy.
  * For each user when the condition is to be generated, first get the subordinate user if any
  * And then generate the condition. Each table (entity - contacts,leads,potentials etc) will have 
  * iduser representing who is owner of the record.
  * @param string $entity_table_name
  * @param integer $idmodule
  * @param boolean $subordinate_users_data
  * @param integer $iduser
  * @see modules/User/User.class.php
  */
 public function get_user_where_condition($entity_table_name, $idmodule, $subordinate_users_data = true, $iduser = '')
 {
     if ($iduser == '') {
         $iduser = $_SESSION["do_user"]->iduser;
     }
     $module_data_share_permissions = $_SESSION["do_user"]->get_module_data_share_permissions();
     $where = '';
     //if($idmodule == 7 ) return " where 1=1 ";
     if ($subordinate_users_data === true) {
         if ($module_data_share_permissions[$idmodule] == 5) {
             return " AND `" . $entity_table_name . "`.`iduser` = " . $iduser;
         }
         if ($_SESSION["do_user"]->is_admin == 1) {
             return "";
         }
     }
     if ($module_data_share_permissions[$idmodule] == 1 || $module_data_share_permissions[$idmodule] == 2 || $module_data_share_permissions[$idmodule] == 3) {
         // if the datashare permission is public then display all
         $where = '';
     } elseif ($module_data_share_permissions[$idmodule] == 5) {
         $where = " AND `" . $entity_table_name . "`.`iduser` = " . $iduser;
     } else {
         if ($_SESSION["do_user"]->iduser > 0) {
             $subordinate_users = $_SESSION["do_user"]->get_subordinate_users();
             $user_to_groups = $_SESSION["do_user"]->get_user_associated_to_groups();
         } else {
             $do_user = new User();
             $do_group_user_rel = new GroupUserRelation();
             $subordinate_users = $do_user->get_subordinate_users_by_iduser($iduser);
             $user_to_groups = $do_group_user_rel->get_groups_by_user($iduser, $subordinate_users);
         }
         $group_qry = false;
         if (is_array($user_to_groups) && count($user_to_groups) > 0) {
             $do_module = new Module();
             $do_module->getId($idmodule);
             $module_name = $do_module->name;
             $entity_object = new $module_name();
             if ($entity_object->module_group_rel_table != '') {
                 $group_qry = true;
             }
         }
         if (is_array($subordinate_users) && count($subordinate_users) > 0 && $subordinate_users_data === true) {
             $unique_subordinate_users = array_unique($subordinate_users);
             $comma_seperated_subordinate_users = implode(",", $unique_subordinate_users);
             if ($group_qry === true) {
                 $where = " \n\t\t\t\t\tAND \n\t\t\t\t\t(\n\t\t\t\t\t\t( " . $entity_table_name . ".iduser = "******" \n\t\t\t\t\t\t\tOR " . $entity_table_name . ".iduser IN (" . $comma_seperated_subordinate_users . ") \n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR (" . $entity_object->module_group_rel_table . ".idgroup in (" . implode(",", $user_to_groups) . ") )\n\t\t\t\t\t)";
             } else {
                 $where = " AND ( " . $entity_table_name . ".iduser = "******" OR " . $entity_table_name . ".iduser IN (" . $comma_seperated_subordinate_users . ") )";
             }
         } else {
             if ($group_qry === true) {
                 $where = " AND ( " . $entity_table_name . ".iduser = "******" OR " . $entity_object->module_group_rel_table . ".idgroup in (" . implode(",", $user_to_groups) . ") )";
             } else {
                 $where = " AND " . $entity_table_name . ".iduser = " . $iduser;
             }
         }
     }
     return $where;
 }