Exemplo n.º 1
0
 /**
  * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
  *
  * @param	User	$user   Objet user
  * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
  */
 function load_board($user)
 {
     global $conf, $user, $langs;
     $sql = "SELECT a.id, a.datep as dp";
     $sql .= " FROM (" . MAIN_DB_PREFIX . "actioncomm as a";
     $sql .= ")";
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
     }
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid";
     $sql .= " WHERE a.percent >= 0 AND a.percent < 100";
     $sql .= " AND a.entity IN (" . getEntity('actioncomm', 1) . ")";
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = "******")";
     }
     if ($user->societe_id) {
         $sql .= " AND a.fk_soc = " . $user->societe_id;
     }
     if (!$user->rights->agenda->allactions->read) {
         $sql .= " AND (a.fk_user_author = " . $user->id . " OR a.fk_user_action = " . $user->id . " OR a.fk_user_done = " . $user->id . ")";
     }
     $resql = $this->db->query($sql);
     if ($resql) {
         $agenda_static = new ActionComm($this->db);
         $response = new WorkboardResponse();
         $response->warning_delay = $conf->actions->warning_delay / 60 / 60 / 24;
         $response->label = $langs->trans("ActionsToDo");
         $response->url = DOL_URL_ROOT . '/comm/action/listactions.php?status=todo&amp;mainmenu=agenda';
         $response->img = img_object($langs->trans("Actions"), "action");
         // This assignment in condition is not a bug. It allows walking the results.
         while ($obj = $this->db->fetch_object($resql)) {
             $response->nbtodo++;
             $agenda_static->datep = $this->db->jdate($obj->dp);
             if ($agenda_static->hasDelay()) {
                 $response->nbtodolate++;
             }
         }
         return $response;
     } else {
         $this->error = $this->db->error();
         return -1;
     }
 }