noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
user_common.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 
00021 
00022 
00023 
00024 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00025 
00026 require_once('class_database.php');
00027 require_once("class_icheckbox.php");
00028 require_once("class_ihidden.php");
00029 require_once("class_document.php");
00030 require_once("class_acc_operation.php");
00031 /*! \file
00032  * \brief Common functions
00033  */
00034 
00035 /*!
00036  *\brief   test if a jrn op is valid
00037  *
00038  * \param $p_cn db
00039  * \param $p_grpt_id
00040  * \return:
00041  *        - 1 is valid
00042  *        - 0 is not valid
00043  */
00044 function isValid_deprecrated ($p_cn,$p_grpt_id)
00045 {
00046     $Res=$p_cn->exec_sql("select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
00047 
00048     if ( ( $M = Database::num_row($Res)) == 0 ) return 0;
00049 
00050     $a=Database::fetch_array($Res,0);
00051 
00052     if ( $a['jr_valid'] == 't') return 1;
00053     if ( $a['jr_valid'] == 'f') return 0;
00054 
00055     echo_error ("Invalid result = ".$a['result']);
00056 
00057 
00058 }
00059 
00060 /*!
00061  **************************************************
00062  *\brief
00063  *     Create a navigation_bar (pagesize)
00064  *
00065  * \param $p_offset first record number
00066  * \param $p_line total of returned row
00067  * \param $p_size current g_pagesize user's preference
00068  * \param $p_page number of the page where the user is
00069  * \param $p_javascript javascript code to add
00070  * \note example :
00071 \verbatim
00072    $step=$_SESSION['g_pagesize'];
00073    $page=(isset($_GET['offset']))?$_GET['page']:1;
00074    $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00075 
00076    list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
00077    $bar=navigation_bar($offset,$max_ligne,$step,$page);
00078 \endverbatim
00079  * \return   string with the nav. bar
00080  */
00081 function navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="")
00082 {
00083     // if the pagesize is unlimited return ""
00084     // in that case there is no nav. bar
00085     if ( $_SESSION['g_pagesize'] == -1  ) return "";
00086     if ( $p_size==0)
00087     {
00088         $p_size= $_SESSION['g_pagesize'];
00089     }
00090     // if there is no row return an empty string
00091     if ( $p_line == 0 ) return "";
00092 
00093     // Clean url, cut away variable coming frm here
00094     $url=cleanUrl();
00095     // action to clean
00096     $url=str_replace('&p_action=delete','',$url);
00097 
00098     // compute max of page
00099     $nb_page=($p_line-($p_line%$p_size))/$p_size;
00100     // if something remains
00101     if ( $p_line % $p_size != 0 ) $nb_page+=1;
00102 
00103     // if max page == 1 then return a empty string
00104     if ( $nb_page == 1) return "";
00105 
00106     // restore the sort
00107     if ( isset($_GET['o']))
00108         $url=$url.'&o='.$_GET['o'];
00109 
00110     $r="";
00111     // previous
00112     if ($p_page !=1)
00113     {
00114         $e=$p_page-1;
00115         $step=$p_size;
00116         $offset=($e-1)*$step;
00117 
00118         $r='<A class="mtitle" href="'.basename($_SERVER['SCRIPT_FILENAME'])."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.'>';
00119         $r.="   &larr;";
00120         // $r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-previous.png">';
00121         $r.="</A>&nbsp;&nbsp;";
00122     }
00123     //----------------------------------------------------------------------
00124     // Create a partial bar
00125     // if current page < 11 show 1 to 20
00126     // otherwise            show $p_page -10 to $p_page + 10
00127     //----------------------------------------------------------------------
00128     $start_bar=($p_page < 11 )?1:$p_page-10;
00129     $end_bar  =($p_page < 11 )?20:$p_page+10;
00130     $end_bar  =($end_bar > $nb_page )?$nb_page:$end_bar;
00131 
00132         $sep="";
00133     // Create the bar
00134     for ($e=$start_bar;$e<=$end_bar;$e++)
00135     {
00136         // do not included current page
00137         if ( $e != $p_page )
00138         {
00139             $step=$p_size;
00140             $offset=($e-1)*$step;
00141 
00142             $go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step";
00143                         $r.=$sep;
00144             $r.=sprintf('<A class="nav" HREF="%s"  %s >%d</A>&nbsp;',$go,$p_javascript,$e);
00145                         $sep=" &#8231;  ";
00146         }
00147         else
00148         {
00149                         $r.=$sep;
00150             $r.="<b> [ $e ] </b>";
00151                         $sep=" &#8231;  ";
00152         } //else
00153     } //for
00154     // next
00155 
00156     if ($p_page !=$nb_page)
00157     {
00158         // If we are not at the last page show the button next
00159         $e=$p_page+1;
00160         $step=$p_size;
00161         $offset=($e-1)*$step;
00162 
00163         $r.='&nbsp;<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'" '.$p_javascript.' >';
00164         $r.="&rarr;";
00165         //$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-next.png">';
00166         $r.="</A>";
00167     }
00168 
00169 
00170     return $r;
00171 }
00172 
00173 /*!
00174  * \brief Clean the url, remove the $_GET offset,step, page and size
00175  * \param none
00176  *
00177  * \return the cleaned url
00178  */
00179 
00180 function CleanUrl()
00181 {
00182     // Compute the url
00183     $url="";
00184     $and="";
00185     $get=$_GET;
00186     if ( isset ($get) )
00187     {
00188         foreach ($get as $name=>$value )
00189         {
00190             // we clean the parameter offset, step, page and size
00191             if (  ! in_array($name,array('offset','step','page','size','s','o','r_jrn')))
00192             {
00193                 $url.=$and.$name."=".$value;
00194                 $and="&";
00195             }// if
00196         }//foreach
00197         if ( isset($_GET['r_jrn']))
00198         {
00199             $r_jrn=$_GET['r_jrn'];
00200             if (count($r_jrn) > 0 )
00201             {
00202                 foreach ($r_jrn as $key=>$value)
00203                 {
00204                     $url.=$and."r_jrn[$key]=".$value;
00205                     $and="&";
00206                 }
00207             }
00208         }
00209     }// if
00210     return $url;
00211 }
00212 function redirect($p_string,$p_time=0)
00213 {
00214     echo '<HTML><head><META HTTP-EQUIV="REFRESH" content="'.$p_time.';url='.$p_string.'"></head><body> Connecting... </body></html>';
00215 }
00216 /*!\brief remove the useless space, change comma by period and try to return
00217  * a number
00218  *\param $p_num number to format
00219  *\return the formatted number
00220  */
00221 function toNumber($p_num)
00222 {
00223     $p_num=trim($p_num);
00224     if ($p_num=='') return 0;
00225     $p_num=str_replace("'",'',$p_num);
00226     $p_num=str_replace(',','.',$p_num);
00227     return $p_num;
00228 }
00229 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations