Beispiel #1
0
 /**
  * bool search(int $type, array $word, int $page, string $logical, int $limitFrom = 0)
  *
  * Executes a query search
  *
  * @param int $type one of the global constants
  * @param array (string) $word string(s) to search for
  * @param int $page What page should be returned if results are more than one page
  * @param string $logical logical operator to concatenate string(s) to search for
  * @param int $limitFrom (optional) maximum number of results
  * @return boolean returns false, if error occurs
  * @access public
  */
 function search($type, $word, $page, $logical, $limitFrom = 0)
 {
     parent::_resetStats($page);
     // Building sql statements
     switch ($type) {
         case OPEN_SEARCH_SURNAME1:
             $field = $this->_table . "." . "surname1";
             break;
         case OPEN_SEARCH_SURNAME2:
             $field = $this->_table . "." . "surname2";
             break;
         case OPEN_SEARCH_FIRSTNAME:
             $field = $this->_table . "." . "first_name";
             break;
         case OPEN_SEARCH_NIF:
             $field = $this->_table . "." . "nif";
             break;
         case OPEN_SEARCH_NTS:
             $field = $this->_table . "." . "nts";
             break;
         case OPEN_SEARCH_NSS:
             $field = $this->_table . "." . "nss";
             break;
         case OPEN_SEARCH_BIRTHPLACE:
             $field = $this->_table . "." . "birth_place";
             break;
         case OPEN_SEARCH_ADDRESS:
             $field = $this->_table . "." . "address";
             break;
         case OPEN_SEARCH_PHONE:
             $field = $this->_table . "." . "phone_contact";
             break;
         case OPEN_SEARCH_INSURANCE:
             $field = $this->_table . "." . "insurance_company";
             break;
         case OPEN_SEARCH_COLLEGIATE:
             $field = "staff_tbl.collegiate_number";
             break;
         default:
             $field = "no_field";
             break;
     }
     // Building sql statements
     $sql = " FROM " . $this->_table . " LEFT JOIN staff_tbl ON " . $this->_table . ".id_member=staff_tbl.id_member";
     $sql .= " WHERE ";
     $num = sizeof($word);
     if ($num > 1) {
         for ($i = 0; $i < $num - 1; $i++) {
             if ($logical == OPEN_NOT) {
                 $sql .= $field . " NOT LIKE '%" . $word[$i] . "%' AND ";
             } else {
                 $sql .= $field . " LIKE '%" . $word[$i] . "%' " . $logical . " ";
             }
         }
     }
     if ($logical == OPEN_NOT) {
         $sql .= $field . " NOT LIKE '%" . $word[$num - 1] . "%'";
     } else {
         $sql .= $field . " LIKE '%" . $word[$num - 1] . "%'";
     }
     $sqlCount = "SELECT COUNT(*) AS row_count " . $sql;
     $sql = "SELECT " . $this->_table . ".*, staff_tbl.collegiate_number, FLOOR((TO_DAYS(GREATEST(IF(decease_date='0000-00-00',CURRENT_DATE,decease_date),IFNULL(decease_date,CURRENT_DATE))) - TO_DAYS(birth_date)) / 365) AS age " . $sql;
     $sql .= " ORDER BY " . $this->_table . ".surname1, " . $this->_table . ".surname2, " . $this->_table . ".first_name";
     // setting limit so we can page through the results
     $offset = ($this->_currentPage - 1) * intval($this->_itemsPerPage);
     if ($offset >= $limitFrom && $limitFrom > 0) {
         $offset = 0;
     }
     $limitTo = intval($this->_itemsPerPage);
     if ($limitTo > 0) {
         $sql .= " LIMIT " . $offset . "," . $limitTo . ";";
     }
     //Error::debug($limitFrom, "limitFrom"); // debug
     //Error::debug($offset, "offset"); // debug
     //Error::debug($sql, "sql"); // debug
     // Running row count sql statement
     if (!$this->exec($sqlCount)) {
         return false;
     }
     $array = parent::fetchRow();
     parent::_calculateStats($array["row_count"], $limitFrom);
     if (!$this->getRowCount()) {
         return false;
     }
     // Running search sql statement
     return $this->exec($sql);
 }
Beispiel #2
0
 /**
  * bool searchUser(int $idUser, int $page, int $limitFrom = 0)
  *
  * Executes a query
  *
  * @param int $idUser
  * @param int $page What page should be returned if results are more than one page
  * @param int $limitFrom (optional) maximum number of results
  * @return boolean returns false, if error occurs
  * @access public
  * @since 0.7
  */
 function searchUser($idUser, $page, $limitFrom = 0)
 {
     parent::_resetStats($page);
     $sql = " FROM " . $this->_table;
     $sql .= " WHERE id_user="******"SELECT COUNT(*) AS row_count" . $sql;
     $sql = "SELECT login,access_date,id_profile" . $sql;
     $sql .= " ORDER BY access_date DESC";
     // setting limit so we can page through the results
     $offset = ($this->_currentPage - 1) * intval($this->_itemsPerPage);
     if ($offset >= $limitFrom && $limitFrom > 0) {
         $offset = 0;
     }
     $limitTo = intval($this->_itemsPerPage);
     if ($limitTo > 0) {
         $sql .= " LIMIT " . $offset . "," . $limitTo . ";";
     }
     //Error::debug($limitFrom, "limitFrom"); // debug
     //Error::debug($offset, "offset"); // debug
     //Error::debug($sql, "sql"); // debug
     // Running row count sql statement
     if (!$this->exec($sqlCount)) {
         return false;
     }
     $array = parent::fetchRow();
     parent::_calculateStats($array["row_count"], $limitFrom);
     if (!$this->getRowCount()) {
         return false;
     }
     // Running search sql statement
     return $this->exec($sql);
 }
Beispiel #3
0
 /**
  * bool search(int $type, array $word, int $page, string $logical, int $limitFrom = 0)
  *
  * Executes a query search
  *
  * @param int $type one of the global constants
  * @param array (string) $word string(s) to search for
  * @param int $page What page should be returned if results are more than one page
  * @param string $logical logical operator to concatenate string(s) to search for
  * @param int $limitFrom (optional) maximum number of results
  * @return boolean returns false, if error occurs
  * @access public
  * @since 0.4
  */
 function search($type, $word, $page, $logical, $limitFrom = 0)
 {
     parent::_resetStats($page);
     // Building sql statements
     switch ($type) {
         case OPEN_SEARCH_WORDING:
             $field = "wording";
             break;
         case OPEN_SEARCH_SUBJECTIVE:
             $field = "subjective";
             break;
         case OPEN_SEARCH_OBJECTIVE:
             $field = "objective";
             break;
         case OPEN_SEARCH_APPRECIATION:
             $field = "appreciation";
             break;
         case OPEN_SEARCH_ACTIONPLAN:
             $field = "action_plan";
             break;
         case OPEN_SEARCH_PRESCRIPTION:
             $field = "prescription";
             break;
         default:
             $field = "no_field";
             break;
     }
     // Building sql statements
     $sql = " FROM " . $this->_table . " LEFT JOIN staff_tbl ON " . $this->_table . ".id_member=staff_tbl.id_member";
     $sql .= " WHERE ";
     $num = sizeof($word);
     if ($num > 1) {
         for ($i = 0; $i < $num - 1; $i++) {
             if ($logical == OPEN_NOT) {
                 $sql .= $field . " NOT LIKE '%" . $word[$i] . "%' AND ";
             } else {
                 $sql .= $field . " LIKE '%" . $word[$i] . "%' " . $logical . " ";
             }
         }
     }
     if ($logical == OPEN_NOT) {
         $sql .= $field . " NOT LIKE '%" . $word[$num - 1] . "%'";
     } else {
         $sql .= $field . " LIKE '%" . $word[$num - 1] . "%'";
     }
     $sqlCount = "SELECT COUNT(*) AS row_count " . $sql;
     $sql = "SELECT " . $this->_table . ".*, staff_tbl.collegiate_number " . $sql;
     $sql .= " ORDER BY " . $field;
     // setting limit so we can page through the results
     $offset = ($this->_currentPage - 1) * intval($this->_itemsPerPage);
     if ($offset >= $limitFrom && $limitFrom > 0) {
         $offset = 0;
     }
     $limitTo = intval($this->_itemsPerPage);
     if ($limitTo > 0) {
         $sql .= " LIMIT " . $offset . "," . $limitTo . ";";
     }
     //Error::debug($limitFrom, "limitFrom"); // debug
     //Error::debug($offset, "offset"); // debug
     //Error::debug($sql, "sql"); // debug
     // Running row count sql statement
     if (!$this->exec($sqlCount)) {
         return false;
     }
     $array = parent::fetchRow();
     parent::_calculateStats($array["row_count"], $limitFrom);
     if (!$this->getRowCount()) {
         return false;
     }
     // Running search sql statement
     return $this->exec($sql);
 }