noalyss Version-9
user_common.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
20
21
22
23
24// Copyright Author Dany De Bontridder danydb@aevalys.eu
25
26/*! \file
27 * \brief Common functions
28 */
29
30/*!
31 *\brief test if a jrn op is valid
32 *
33 * \param $p_cn db
34 * \param $p_grpt_id
35 * \return:
36 * - 1 is valid
37 * - 0 is not valid
38 */
39function isValid_deprecrated ($p_cn,$p_grpt_id)
40{
41 $Res=$p_cn->exec_sql("select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
42
43 if ( ( $M = Database::num_row($Res)) == 0 ) return 0;
44
46
47 if ( $a['jr_valid'] == 't') return 1;
48 if ( $a['jr_valid'] == 'f') return 0;
49
50 echo_error ("Invalid result = ".$a['result']);
51
52
53}
54
55/*!
56 **************************************************
57 *\brief
58 * Create a navigation_bar (pagesize)
59 *
60 * \param $p_offset first record number
61 * \param $p_line total of returned row
62 * \param $p_size current g_pagesize user's preference
63 * \param $p_page number of the page where the user is
64 * \param $p_javascript javascript code to add
65 * \note example :
66\verbatim
67 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
68 $page=(isset($_GET['offset']))?$_GET['page']:1;
69 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
70
71 list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
72 $bar=navigation_bar($offset,$max_ligne,$step,$page);
73\endverbatim
74 * \return string with the nav. bar
75 */
76function navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="")
77{
78 // if the pagesize is unlimited return ""
79 // in that case there is no nav. bar
80 if ( $_SESSION[SESSION_KEY.'g_pagesize'] == -1 ) return "";
81 if ( $p_size==0)
82 {
83 $p_size= $_SESSION[SESSION_KEY.'g_pagesize'];
84 }
85 // if there is no row return an empty string
86 if ( $p_line == 0 ) return "";
87
88 // Clean url, cut away variable coming frm here
89 $url=cleanUrl();
90 // action to clean
91 $url=noalyss_str_replace('&p_action=delete','',$url);
92
93 // compute max of page
94 $nb_page=($p_line-($p_line%$p_size))/$p_size;
95 // if something remains
96 if ( $p_line % $p_size != 0 ) $nb_page+=1;
97
98 // if max page == 1 then return a empty string
99 if ( $nb_page == 1) return "";
100
101 // restore the sort
102 if ( isset($_GET['o']))
103 $url=$url.'&o='.$_GET['o'];
104
105 $r="";
106 // previous
107 if ($p_page !=1)
108 {
109 $e=$p_page-1;
110 $step=$p_size;
111 $offset=($e-1)*$step;
112
113 $r='<A class="mtitle" href="'.basename($_SERVER['PHP_SELF'])."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.'>';
114 $r.=" &larr;";
115 // $r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-previous.png">';
116 $r.="</A>&nbsp;&nbsp;";
117 }
118 //----------------------------------------------------------------------
119 // Create a partial bar
120 // if current page < 11 show 1 to 20
121 // otherwise show $p_page -10 to $p_page + 10
122 //----------------------------------------------------------------------
123 $start_bar=($p_page < 11 )?1:$p_page-10;
124 $end_bar =($p_page < 11 )?20:$p_page+10;
125 $end_bar =($end_bar > $nb_page )?$nb_page:$end_bar;
126
127 $sep="";
128 // Create the bar
129 for ($e=$start_bar;$e<=$end_bar;$e++)
130 {
131 // do not included current page
132 if ( $e != $p_page )
133 {
134 $step=$p_size;
135 $offset=($e-1)*$step;
136
137 $go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step";
138 $r.=$sep;
139 $r.=sprintf('<A class="nav" HREF="%s" %s >%d</A>&nbsp;',$go,$p_javascript,$e);
140 $sep=" &#8231; ";
141 }
142 else
143 {
144 $r.=$sep;
145 $r.="<b> [ $e ] </b>";
146 $sep=" &#8231; ";
147 } //else
148 } //for
149 // next
150
151 if ($p_page !=$nb_page)
152 {
153 // If we are not at the last page show the button next
154 $e=$p_page+1;
155 $step=$p_size;
156 $offset=($e-1)*$step;
157
158 $r.='&nbsp;<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.' >';
159 $r.="&rarr;";
160 //$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-next.png">';
161 $r.="</A>";
162 }
163
164
165 return $r;
166}
167
168/*!
169 * \brief Clean the url, remove the $_GET offset,step, page and size
170 * \param none
171 *
172 * \return the cleaned url
173 */
174
175function CleanUrl()
176{
177 // Compute the url
178 $url=http_build_query($_GET);
179 return $url;
180}
181function redirect($p_string,$p_time=0)
182{
183 if (strpos( $p_string,'?') == 0 ) {
184 $p_string = $p_string.'?v='.microtime(true);
185 }
186 echo '<HTML><head><META HTTP-EQUIV="REFRESH" content="'.$p_time.'; url='.$p_string.'"></head><body> Connecting... </body></html>';
187}
188/*!
189 * \brief remove the useless space, change comma by period and try to return
190 * a number
191 *\param $p_num number to format
192 *\return the formatted number
193 */
194function toNumber($p_num)
195{
196 $p_num=trim($p_num);
197 if ($p_num=='') return 0;
198 $p_num=noalyss_str_replace("'",'',$p_num);
199 $p_num=noalyss_str_replace(',','.',$p_num);
200 return $p_num;
201}
202/**
203 * Check that all the index are in the array, used by function to check if
204 * the array contains the needed variables before an extract
205 * @param type $p_array array to check
206 * @param type $needed string containing variable separated by comma
207 * @throws Exception
208 */
209function check_parameter($p_array,$p_needed)
210{
211 $needed =explode(',',$p_needed);
212 for ($e=0;$e<count($needed);$e++) {
213 if ( ! isset($p_array[$needed[$e]])) {
214 throw new Exception (_('Paramètre manquant')." ".$needed[$e]);
215 }
216 }
217}
218/**
219 * sanitize the filename remove character which could be a problem,
220 * @param string $p_filename the filename to clean
221 * @return string Filename without bad char.
222 */
223function clean_filename($p_filename)
224{
225 $filename=$p_filename;
226 foreach (array('/','*','<','>',';',',','\\',':','(',')',' ','[',']') as $i) {
227 $filename= noalyss_str_replace($i, "-",$filename);
228 }
229 return $filename;
230
231}
232?>
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
Definition: ac_common.php:169
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$url
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
$_GET['qcode']
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
$Res
isValid_deprecrated($p_cn, $p_grpt_id)
test if a jrn op is valid
Definition: user_common.php:39
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...
clean_filename($p_filename)
sanitize the filename remove character which could be a problem,
CleanUrl()
Clean the url, remove the $_GET offset,step, page and size.
redirect($p_string, $p_time=0)
toNumber($p_num)
remove the useless space, change comma by period and try to return a number
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:76