noalyss Version-9
contact.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20//!\brief class for the contact, contact are derived from fiche
21require_once NOALYSS_INCLUDE.'/constant.php';
22require_once NOALYSS_INCLUDE.'/lib/user_common.php';
23/*! \file
24 * \brief Contact are a card which are own by a another card (customer, supplier...)
25 */
26/*!
27 * \brief Class contact (customer, supplier...)
28 */
29
30class contact extends Fiche
31{
32 private $filter;
33
34 /*!\brief constructor */
35 function __construct($p_cn,$p_id=0)
36 {
37 $this->fiche_def_ref=FICHE_TYPE_CONTACT;
38 parent::__construct($p_cn,$p_id) ;
39 $this->filter=[];
40 }
41
42 /**
43 * @brief Build the SQL query thanks the parameter
44 * @param array $array if empty , we use $this->filter , otherwise $array will override it
45 * @return string
46 */
47 function build_sql($array)
48 {
49 if ( empty($array) ) $array=$this->filter;
50
51 $sql_query='
52 SELECT f_id,
53 contact_fname,
54 contact_name,
55 contact_qcode,
56 contact_company,
57 contact_mobile,
58 contact_phone,
59 contact_email,
60 contact_fax
61 FROM public.v_contact
62 ';
63 $where=' where ';$and='';
64 if ( isset ($array['company'])) {
65 $sql_query.=$where.sprintf(" contact_company ilike '%%%s%%'",
66 sql_string($array['company']));
67 $where='';$and=' and ';
68 }
69 if ( isset($array['search'])) {
70 $sql_query.=$where.$and.sprintf(" f_id in (select distinct f_id from fiche_detail where ad_value ilike '%%%s%%')",
71 sql_string($array['search']));
72 $where='';$and=' and ';
73
74 }
75 if ( isset($array['category'])) {
76 $sql_query.=$where.$and.sprintf(" fd_id = %s",
77 sql_string($array['category']));
78 $where='';$and=' and ';
79 }
80 if ( isset ($array['active']) && $array['active'] == true) {
81 $sql_query .= $where.$and.sprintf(" f_enable='1' ");
82 $where='';$and=' and ';
83 }
84 return $sql_query;
85 }
86 function filter_active(bool $p_active) {
87 if ( $p_active) {
88 $this->filter['active']=true;
89 } else {
90 $this->filter['active']=false;
91 }
92 }
93 function filter_category($pn_category) {
94 unset($this->filter['category']);
95 if ( !empty($pn_category)
96 && isNumber($pn_category)==1
97 && $pn_category != -1){
98 $this->filter['category']=$pn_category;
99 }
100 }
101 function filter_company($p_company=null) {
102 unset($this->filter['company']);
103 if ( ! empty($p_company) && $p_company != "-1") {
104 $this->filter['company']= strtoupper($p_company);
105 }
106 return $this;
107 }
108 function filter_search($p_search="") {
109 unset($this->filter['search']);
110 if ( ! empty($p_search) ){
111 $this->filter['search']=$p_search;
112 }
113 }
114
115 /**
116 * @return array
117 */
118 public function getFilter(): array
119 {
120 return $this->filter;
121 }
122
123 /*!
124 * @brief display a summary of the contact card,
125 *
126 * @param string p_search : filter on card name, if empty , contact->filter will be used
127 * @param string p_action : not used
128 * @param string p_sql : extra SQL command not used
129 * @param string p_nothing (filter) not used
130 *
131 * @returns string to display
132 */
133 function Summary($p_search="",$p_action="",$p_sql="",$p_nothing=false)
134 {
135 $http=new HttpInput();
136 if ( !empty ($p_search) ) { $this->filter_search($p_search);}
137
138 $sql=$this->build_sql($this->filter);
139 \Noalyss\Dbg::echo_var(1,"Contact::summary ($sql)");
140 // Creation of the nav bar
141 // Get the max numberRow
142 $all_contact=$this->cn->get_value("select count(*) from ($sql) as m");
143 if ( $all_contact == 0 ) return "";
144
145 // Get offset and page variable
146 $offset=$http->request('offset','number',0);
147 $page=$http->request('page','number',1);
148
149 $bar=navigation_bar($offset,$all_contact,$_SESSION[SESSION_KEY.'g_pagesize'],$page);
150
151
152 // Get The result Array
153 $step_contact=$this->fetch($sql);
154
155
156 $contact=$this;
157 require NOALYSS_TEMPLATE.'/contact-summary.php';
158
159 }
160
161 /**
162 * @brief Fetch all rows from view, ordered by by contact_name, with offset and limit
163 * @see Contact::build_sql()
164 * @param $ps_string
165 * @return array
166 */
167 private function fetch($ps_sql) {
168 $http=new HttpInput();
169 // Get offset and page variable
170 $offset=$http->request('offset','number',0);
171 $nb_pagesize=$_SESSION[SESSION_KEY.'g_pagesize'];
172 $limit = '';
173 $ps_sql.=' order by contact_name ';
174 if ( $nb_pagesize <0 ) {$limit='';} else {
175 $limit=sprintf(' limit %s offset %s',$nb_pagesize,$offset);
176 }
177 $ps_sql .= $limit ;
178 if (DEBUGNOALYSS > 1) {
179 var_export("Contact::fetch ($ps_sql)");
180 }
181 return $this->cn->get_array($ps_sql);
182 }
183}
isNumber($p_int)
Definition: ac_common.php:215
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
$input_from cn
Definition: balance.inc.php:66
if(! isset($_GET['submit_query'])) $p_action
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
manage the http input (get , post, request) and extract from an array
static echo_var($n_level, $msg, $print=true)
Display the value of a var if DEBUGNOALYSS is greater than $n_level, the debugging info has a certain...
Definition: dbg.php:45
Class contact (customer, supplier...)
build_sql($array)
Build the SQL query thanks the parameter.
Summary($p_search="", $p_action="", $p_sql="", $p_nothing=false)
display a summary of the contact card,
fetch($ps_sql)
Fetch all rows from view, ordered by by contact_name, with offset and limit.
filter_search($p_search="")
filter_company($p_company=null)
filter_category($pn_category)
__construct($p_cn, $p_id=0)
constructor
filter_active(bool $p_active)
const FICHE_TYPE_CONTACT
Definition: constant.php:251
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:76