Author: danydb Date: 2011-10-29 04:36:11 +0200 (Sat, 29 Oct 2011) New Revision: 4264
Added: phpcompta/trunk/include/extension_choice.inc.php phpcompta/trunk/include/extension_get.inc.php Removed: phpcompta/trunk/include/ext_inc.php Modified: phpcompta/trunk/include/ac_common.php Log: 424 : plugin dans les menus ou modules Modified: phpcompta/trunk/include/ac_common.php =================================================================== --- phpcompta/trunk/include/ac_common.php 2011-10-29 01:21:42 UTC (rev 4263) +++ phpcompta/trunk/include/ac_common.php 2011-10-29 02:36:11 UTC (rev 4264) @@ -1,4 +1,5 @@ <?php + /* * This file is part of PhpCompta. * @@ -15,10 +16,10 @@ * You should have received a copy of the GNU General Public License * along with PhpCompta; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ // Copyright Author Dany De Bontridder [email protected] -/*! \file +/* ! \file * \brief common utilities for a lot of procedure, classe */ @@ -26,88 +27,108 @@ require_once('class_database.php'); require_once('class_periode.php'); -/*!\brief to protect again bad characters which can lead to a cross scripting attack - the string to be diplayed must be protected -*/ +/* !\brief to protect again bad characters which can lead to a cross scripting attack + the string to be diplayed must be protected + */ + function h($p_string) { return htmlspecialchars($p_string); } -function span($p_string,$p_extra='') + +function span($p_string, $p_extra='') { - return '<span '.$p_extra.'>'.$p_string.'</span>'; + return '<span ' . $p_extra . '>' . $p_string . '</span>'; } + function hi($p_string) { - return '<i>'.htmlspecialchars($p_string).'</i>'; + return '<i>' . htmlspecialchars($p_string) . '</i>'; } + function hb($p_string) { - return '<b>'.htmlspecialchars($p_string).'</b>'; + return '<b>' . htmlspecialchars($p_string) . '</b>'; } -function th($p_string,$p_extra='') + +function th($p_string, $p_extra='') { - return '<th '.$p_extra.'>'.htmlspecialchars($p_string).'</th>'; + return '<th ' . $p_extra . '>' . htmlspecialchars($p_string) . '</th>'; } + function h2info($p_string) { - return '<h2 class="info">'.htmlspecialchars($p_string).'</h2>'; + return '<h2 class="info">' . htmlspecialchars($p_string) . '</h2>'; } -function h2($p_string,$p_class) + +function h2($p_string, $p_class) { - return '<h2 '.$p_class.'>'.htmlspecialchars($p_string).'</h2>'; + return '<h2 ' . $p_class . '>' . htmlspecialchars($p_string) . '</h2>'; } -/*!\brief surround the string with td -*\param $p_string string to surround by TD -*\param $p_extra extra info (class, style, javascript...) -* \return string surrounded by td -*/ -function td($p_string='',$p_extra='') +/* !\brief surround the string with td + * \param $p_string string to surround by TD + * \param $p_extra extra info (class, style, javascript...) + * \return string surrounded by td + */ + +function td($p_string='', $p_extra='') { - return '<td '.$p_extra.'>'.$p_string.'</td>'; + return '<td ' . $p_extra . '>' . $p_string . '</td>'; } -function tr($p_string,$p_extra='') + +function tr($p_string, $p_extra='') { - return '<tr '.$p_extra.'>'.$p_string.'</tr>'; + return '<tr ' . $p_extra . '>' . $p_string . '</tr>'; } -/*!\brief escape correctly php string to javascript */ + +/* !\brief escape correctly php string to javascript */ + function j($p_string) { - $a=preg_replace("/\r?\n/", "\\n", addslashes($p_string)); - $a=str_replace("'",'\'',$a); + $a = preg_replace("/\r?\n/", "\\n", addslashes($p_string)); + $a = str_replace("'", '\'', $a); return $a; } + /** * format the number for the CSV export - *@param $p_number number + * @param $p_number number */ function nb($p_number) { - $r=sprintf('%.2f',$p_number); - $r=str_replace('.',',',$r); + $r = sprintf('%.2f', $p_number); + $r = str_replace('.', ',', $r); - return $r; + return $r; } + /** * format the number with a sep. for the thousand - *@param $p_number number + * @param $p_number number */ function nbm($p_number) { - if (trim($p_number)=='') return ''; - if ( $p_number==0) return 0; - $a=doubleval($p_number); + if (trim($p_number) == '') + return ''; + if ($p_number == 0) + return 0; + $a = doubleval($p_number); - $r=number_format($a,2,",","."); - if (trim($r)=='') { - var_dump($r);var_dump($p_number);var_dump($a);exit(); - } + $r = number_format($a, 2, ",", "."); + if (trim($r) == '') + { + var_dump($r); + var_dump($p_number); + var_dump($a); + exit(); + } - return $r; + return $r; } -/*! + +/* ! * \brief log error into the /tmp/phpcompta_error.log it doesn't work on windows * * \param p_log message @@ -117,18 +138,19 @@ * \return nothing * */ -function echo_error ($p_log, $p_line="", $p_message="") + +function echo_error($p_log, $p_line="", $p_message="") { - echo "ERREUR :".$p_log." ".$p_line." ".$p_message; - $fdebug=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR."phpcompta_error.log","a+"); - if ($fdebug != null ) + echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message; + $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "phpcompta_error.log", "a+"); + if ($fdebug != null) { - fwrite($fdebug,date("Ymd H:i:s").$p_log." ".$p_line." ".$p_message."\n"); - fclose($fdebug); + fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " . $p_message . "\n"); + fclose($fdebug); } } -/*! +/* ! * \brief Compare 2 dates * \param p_date * \param p_date_oth @@ -138,24 +160,26 @@ * - > 0 date1 > date2 * - < 0 date1 < date2 */ -function cmpDate ($p_date,$p_date_oth) + +function cmpDate($p_date, $p_date_oth) { - date_default_timezone_set ('Europe/Brussels'); + date_default_timezone_set('Europe/Brussels'); - $l_date=isDate($p_date); - $l2_date=isDate($p_date_oth); - if ($l_date == null || $l2_date == null ) + $l_date = isDate($p_date); + $l2_date = isDate($p_date_oth); + if ($l_date == null || $l2_date == null) { - throw new Exception ("erreur date [$p_date] [$p_date_oth]"); + throw new Exception("erreur date [$p_date] [$p_date_oth]"); } - $l_adate=explode(".",$l_date); - $l2_adate=explode(".",$l2_date); - $l_mkdate=mktime(0,0,0,$l_adate[1],$l_adate[0],$l_adate[2]); - $l2_mkdate=mktime(0,0,0,$l2_adate[1],$l2_adate[0],$l2_adate[2]); + $l_adate = explode(".", $l_date); + $l2_adate = explode(".", $l2_date); + $l_mkdate = mktime(0, 0, 0, $l_adate[1], $l_adate[0], $l_adate[2]); + $l2_mkdate = mktime(0, 0, 0, $l2_adate[1], $l2_adate[0], $l2_adate[2]); // si $p_date > $p_date_oth return > 0 - return $l_mkdate-$l2_mkdate; + return $l_mkdate - $l2_mkdate; } -/*! + +/* ! * \brief check if the argument is a number * * \param $p_int number to test @@ -164,57 +188,58 @@ * - 1 it's a number * - 0 it is not */ + function isNumber(&$p_int) { - if ( strlen (trim($p_int)) == 0 ) return 0; - if ( is_numeric($p_int) === true) - return 1; + if (strlen(trim($p_int)) == 0) + return 0; + if (is_numeric($p_int) === true) + return 1; else - return 0; - - + return 0; } -/*! +/* ! * \brief Verifie qu'une date est bien formaté * en d.m.y et est valable * \param $p_date * * \return - * - null si la date est invalide ou malformaté + * - null si la date est invalide ou malformaté * - $p_date si tout est bon * */ -function isDate ( $p_date) +function isDate($p_date) { - if ( strlen (trim($p_date)) == 0 ) return null; - if ( preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/",$p_date) == 0 ) + if (strlen(trim($p_date)) == 0) + return null; + if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0) { - return null; + return null; } else { - $l_date=explode(".",$p_date); + $l_date = explode(".", $p_date); - if ( sizeof ($l_date) != 3 ) - return null; + if (sizeof($l_date) != 3) + return null; - if ( $l_date[2] > 2020 ) - { - return null; - } + if ($l_date[2] > 2020) + { + return null; + } - if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) - { - return null; - } - + if (checkdate($l_date[1], $l_date[0], $l_date[2]) == false) + { + return null; + } }// !ereg return $p_date; } -/*! + +/* ! * \brief Default page header for each page * * \param p_theme default theme @@ -223,38 +248,39 @@ * * \return none */ -function html_page_start($p_theme="",$p_script="",$p_script2="") + +function html_page_start($p_theme="", $p_script="", $p_script2="") { - $cn=new Database(); - if ( $p_theme != "") + $cn = new Database(); + if ($p_theme != "") { - $Res=$cn->exec_sql("select the_filestyle from theme - where the_name='".$p_theme."'"); - if (Database::num_row($Res)==0) - $style="style.css"; - else - { - $s=Database::fetch_array($Res,0); - $style=$s['the_filestyle']; - } + $Res = $cn->exec_sql("select the_filestyle from theme + where the_name='" . $p_theme . "'"); + if (Database::num_row($Res) == 0) + $style = "style.css"; + else + { + $s = Database::fetch_array($Res, 0); + $style = $s['the_filestyle']; + } } else { - $style="style.css"; + $style = "style.css"; } // end if echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">'; echo "<HTML>"; - if ( $p_script2 != "" ) - $p_script2='<script src="'.$p_script2.'" type="text/javascript"></script>'; + if ($p_script2 != "") + $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>'; echo "<HEAD> <TITLE>PhpCompta</TITLE> <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\"> <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\"> - <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">". - $p_script2. " + <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" . + $p_script2 . " "; echo '<script language="javascript" src="js/calendar.js"></script> <script type="text/javascript" src="js/lang/calendar-en.js"></script> @@ -265,19 +291,19 @@ echo "<BODY $p_script>"; // language - if ( isset($_SESSION['g_lang'])) + if (isset($_SESSION['g_lang'])) { - set_language(); + set_language(); } /* If we are on the user_login page */ - if ( basename($_SERVER['PHP_SELF']) == 'user_login.php') + if (basename($_SERVER['PHP_SELF']) == 'user_login.php') { - return; + return; } +} -} -/*! +/* ! * \brief Minimal page header for each page, used for small popup window * * \param p_theme default theme @@ -286,102 +312,106 @@ * * \return none */ -function html_min_page_start($p_theme="",$p_script="",$p_script2="") + +function html_min_page_start($p_theme="", $p_script="", $p_script2="") { - $cn=new Database(); - if ( $p_theme != "") + $cn = new Database(); + if ($p_theme != "") { - $Res=$cn->exec_sql("select the_filestyle from theme - where the_name='".$p_theme."'"); - if (Database::num_row($Res)==0) - $style="style.css"; - else - { - $s=Database::fetch_array($Res,0); - $style=$s['the_filestyle']; - } + $Res = $cn->exec_sql("select the_filestyle from theme + where the_name='" . $p_theme . "'"); + if (Database::num_row($Res) == 0) + $style = "style.css"; + else + { + $s = Database::fetch_array($Res, 0); + $style = $s['the_filestyle']; + } } else { - $style="style.css"; + $style = "style.css"; } // end if echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">'; echo "<HTML>"; - if ( $p_script2 != "" ) - $p_script2='<script src="'.$p_script2.'" type="text/javascript"></script>'; + if ($p_script2 != "") + $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>'; echo "<HEAD> <TITLE>PhpCompta</TITLE> <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\"> <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\"> - <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">". - $p_script2. " + <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">" . + $p_script2 . " <script src=\"js/scripts.js\" type=\"text/javascript\"></script>"; echo '</HEAD> '; echo "<BODY $p_script>"; /* If we are on the user_login page */ - if ( basename($_SERVER['PHP_SELF']) == 'user_login.php') + if (basename($_SERVER['PHP_SELF']) == 'user_login.php') { - return; + return; } - } -/*! +/* ! * \brief end tag * */ + function html_page_stop() { echo "</BODY>"; echo "</HTML>"; } -/*! + +/* ! * \brief Echo no access and stop * * \return nothing */ - function NoAccess($js=1) { - if ( $js == 1 ) + if ($js == 1) { - echo "<script>"; - echo "alert ('"._('Cette action ne vous est pas autorisée Contactez votre responsable')."');"; - echo "</script>"; + echo "<script>"; + echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez votre responsable') . "');"; + echo "</script>"; } else { - echo '<div class="u_redcontent">'; - echo '<h2 class="error">'._(' Cette action ne vous est pas autorisée Contactez votre responsable').'</h2>'; - echo '</div>'; + echo '<div class="u_redcontent">'; + echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée Contactez votre responsable') . '</h2>'; + echo '</div>'; } - exit -1; + exit - 1; } -/*! + +/* ! * \brief Fix the problem with the quote char for the database * * \param $p_string * \return a string which won't let strange char for the database */ + function FormatString($p_string) { - $p_string=trim($p_string); - if (strlen($p_string) == 0 ) return null; - $p_string=str_replace("\'","'",$p_string); - $p_string=str_replace("''","'",$p_string); - $p_string=str_replace("'","\'",$p_string); + $p_string = trim($p_string); + if (strlen($p_string) == 0) + return null; + $p_string = str_replace("\'", "'", $p_string); + $p_string = str_replace("''", "'", $p_string); + $p_string = str_replace("'", "\'", $p_string); return $p_string; } -/*! -/* \brief store the string which print +/* ! + /* \brief store the string which print * the content of p_array in a table * used to display the menu * \param $p_array array like ( 0=>HREF reference, 1=>visible item (name),2=>Help(opt), @@ -392,76 +422,79 @@ * \param $default selected item * \param $p_extra extra code for the table tag (CSS or javascript) * -/* \return : string */ -function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$default="",$p_extra="") + /* \return : string */ + +function ShowItem($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", $default="", $p_extra="") { - $ret="<TABLE $p_extra>"; + $ret = "<TABLE $p_extra>"; // direction Vertical - if ( $p_dir == 'V') + if ($p_dir == 'V') { - foreach ($p_array as $all=>$href) - { - $javascript=(isset ($href[4]))?$href[4]:""; - $title=""; - $set="XX"; - if ( isset ($href[2] )) - $title=$href[2]; - if ( isset($href[3] )) - $set=$href[3]; + foreach ($p_array as $all => $href) + { + $javascript = (isset($href[4])) ? $href[4] : ""; + $title = ""; + $set = "XX"; + if (isset($href[2])) + $title = $href[2]; + if (isset($href[3])) + $set = $href[3]; - if ( $set == $default ) - $ret.='<TR><TD CLASS="selectedcell"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'" '.$javascript.'>'.$href[1].'</A></TD></TR>'; - else - $ret.='<TR><TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'" '.$javascript.'>'.$href[1].'</A></TD></TR>'; - } + if ($set == $default) + $ret.='<TR><TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>'; + else + $ret.='<TR><TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD></TR>'; + } } //direction Horizontal - else if ( $p_dir == 'H' ) + else if ($p_dir == 'H') { - $ret.="<TR>"; - foreach ($p_array as $all=>$href) - { - $title=""; - $javascript=(isset ($href[4]))?$href[4]:""; + $ret.="<TR>"; + foreach ($p_array as $all => $href) + { + $title = ""; + $javascript = (isset($href[4])) ? $href[4] : ""; - $set="A"; - if ( isset ($href[2] )) - $title=$href[2]; + $set = "A"; + if (isset($href[2])) + $title = $href[2]; - if ( isset($href[3])) - $set=$href[3]; + if (isset($href[3])) + $set = $href[3]; - if ( $default=== $href[0]||$set===$default ) - { - $ret.='<TD CLASS="selectedcell"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'" '.$javascript.'>'.$href[1].'</A></TD>'; - } - else - { - $ret.='<TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'" '.$javascript.'>'.$href[1].'</A></TD>'; - } - - } - $ret.="</TR>"; + if ($default === $href[0] || $set === $default) + { + $ret.='<TD CLASS="selectedcell"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>'; + } + else + { + $ret.='<TD CLASS="' . $class . '"><A class="' . $class_ref . '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] . '</A></TD>'; + } + } + $ret.="</TR>"; } $ret.="</TABLE>"; return $ret; } -/*! + +/* ! * \brief warns * * \param p_string error message * gen : - * - none + * - none * \return: * - none */ + function echo_warning($p_string) { - echo '<H2 class="error">'.$p_string."</H2>"; + echo '<H2 class="error">' . $p_string . "</H2>"; } -/*! + +/* ! * \brief Show the periode which found thanks its id * * @@ -471,17 +504,17 @@ * * \return: string */ -function getPeriodeName($p_cn,$p_id,$pos='p_start') + +function getPeriodeName($p_cn, $p_id, $pos='p_start') { - if ( $pos != 'p_start' and - $pos != 'p_end') - echo_error('ac_common.php'."-".__LINE__.' UNDEFINED PERIODE'); - $ret=$p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id"); + if ($pos != 'p_start' and + $pos != 'p_end') + echo_error('ac_common.php' . "-" . __LINE__ . ' UNDEFINED PERIODE'); + $ret = $p_cn->get_value("select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id"); return $ret; } - -/*! +/* ! * \brief Return the period corresponding to the * date * @@ -491,27 +524,30 @@ * \return: * parm_periode.p_id */ -function getPeriodeFromMonth($p_cn,$p_date) + +function getPeriodeFromMonth($p_cn, $p_date) { - $R=$p_cn->get_value("select p_id from parm_periode where + $R = $p_cn->get_value("select p_id from parm_periode where to_char(p_start,'DD.MM.YYYY') = '01.$p_date'"); - if ( $R == "" ) - return -1; + if ($R == "") + return -1; return $R; } -/*!\brief Decode the html for the widegt richtext and remove newline - *\param $p_html string to decode + +/* !\brief Decode the html for the widegt richtext and remove newline + * \param $p_html string to decode * \return the html code without new line */ function Decode($p_html) { - $p_html=str_replace('%0D','',$p_html); - $p_html=str_replace('%0A','',$p_html); - $p_html=urldecode($p_html); + $p_html = str_replace('%0D', '', $p_html); + $p_html = str_replace('%0A', '', $p_html); + $p_html = urldecode($p_html); return $p_html; } -/*!\brief Create the condition to filter on the j_tech_per + +/* !\brief Create the condition to filter on the j_tech_per * thanks a from and to date. * \param $p_cn database conx * \param $p_from start date (date) @@ -520,173 +556,182 @@ * \param $p_field column name * \return a string containg the query */ -function sql_filter_per($p_cn,$p_from,$p_to,$p_form='p_id',$p_field='jr_tech_per') + +function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per') { - if ( $p_form != 'p_id' && - $p_form != 'date' ) + if ($p_form != 'p_id' && + $p_form != 'date') { - echo_error (__FILE__,__LINE__,'Mauvais parametres '); - exit(-1); + echo_error(__FILE__, __LINE__, 'Mauvais parametres '); + exit(-1); } - if ( $p_form == 'p_id' ) + if ($p_form == 'p_id') { - // retrieve the date - $pPeriode=new Periode($p_cn); - $a_start=$pPeriode->get_date_limit($p_from); - $a_end=$pPeriode->get_date_limit($p_to); - if ( $a_start == null || $a_end == null ) - throw new Exception(__FILE__.__LINE__.'Attention periode '. - ' non trouvee periode p_from='.$p_from. - 'p_to_periode = '.$p_to); + // retrieve the date + $pPeriode = new Periode($p_cn); + $a_start = $pPeriode->get_date_limit($p_from); + $a_end = $pPeriode->get_date_limit($p_to); + if ($a_start == null || $a_end == null) + throw new Exception(__FILE__ . __LINE__ . 'Attention periode ' . + ' non trouvee periode p_from=' . $p_from . + 'p_to_periode = ' . $p_to); - $p_from=$a_start['p_start']; - $p_to=$a_end['p_end']; + $p_from = $a_start['p_start']; + $p_to = $a_end['p_end']; } - if ( $p_from == $p_to ) - $periode=" $p_field = (select p_id from parm_periode ". - " where ". - " p_start = to_date('$p_from','DD.MM.YYYY')) "; + if ($p_from == $p_to) + $periode = " $p_field = (select p_id from parm_periode " . + " where " . + " p_start = to_date('$p_from','DD.MM.YYYY')) "; else - $periode = "$p_field in (select p_id from parm_periode ". - " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) "; + $periode = "$p_field in (select p_id from parm_periode " . + " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= to_date('$p_to','DD.MM.YYYY')) "; return $periode; } -/*!\brief alert in javascript - *\param $p_msg is the message - *\param $buffer if false, echo directly and execute the javascript, if $buffer is true, the alert javascript +/* !\brief alert in javascript + * \param $p_msg is the message + * \param $buffer if false, echo directly and execute the javascript, if $buffer is true, the alert javascript * is in the return string - *\return string with alert javascript if $buffer is true + * \return string with alert javascript if $buffer is true */ -function alert($p_msg,$buffer=false) + +function alert($p_msg, $buffer=false) { - $r= '<script language="javascript">'; - $r.= 'alert(\''.j($p_msg).'\')'; + $r = '<script language="javascript">'; + $r.= 'alert(\'' . j($p_msg) . '\')'; $r.= '</script>'; - if ($buffer) return $r; + if ($buffer) + return $r; echo $r; +} -} /** - *@brief set the lang thanks the _SESSION['g_lang'] var. + * @brief set the lang thanks the _SESSION['g_lang'] var. */ function set_language() { - $dir=""; + $dir = ""; // set differently the language depending of the operating system - if( what_os() == 1 ) + if (what_os() == 1) { - $dir=setlocale(LC_MESSAGES,$_SESSION['g_lang']); - if ( $dir == "") - { - $g_lang='fr_FR.utf8'; - $dir=setlocale(LC_MESSAGES,$g_lang); - echo '<span class="notice">'.$_SESSION['g_lang'].' domaine non supporté</h2>'; - } - bindtextdomain('messages','./lang'); - textdomain('messages'); - bind_textdomain_codeset('messages','UTF8'); + $dir = setlocale(LC_MESSAGES, $_SESSION['g_lang']); + if ($dir == "") + { + $g_lang = 'fr_FR.utf8'; + $dir = setlocale(LC_MESSAGES, $g_lang); + echo '<span class="notice">' . $_SESSION['g_lang'] . ' domaine non supporté</h2>'; + } + bindtextdomain('messages', './lang'); + textdomain('messages'); + bind_textdomain_codeset('messages', 'UTF8'); - return; + return; } // for windows - putenv('LANG='.$_SESSION['g_lang']); - $dir=setlocale(LC_ALL,$_SESSION['g_lang']); - bindtextdomain('messages','.\\lang'); + putenv('LANG=' . $_SESSION['g_lang']); + $dir = setlocale(LC_ALL, $_SESSION['g_lang']); + bindtextdomain('messages', '.\\lang'); textdomain('messages'); - bind_textdomain_codeset('messages','UTF8'); + bind_textdomain_codeset('messages', 'UTF8'); } + /** - *@brief try to determine on what os you are running the pĥpcompte - *server - *@return + * @brief try to determine on what os you are running the pĥpcompte + * server + * @return * 0 it is a windows * 1 it is a Unix like */ function what_os() { - $inc_path=get_include_path(); + $inc_path = get_include_path(); - if ( strpos($inc_path,";") != 0 ) + if (strpos($inc_path, ";") != 0) { - $os=0; /* $os is 0 for windoz */ + $os = 0; /* $os is 0 for windoz */ } else { - $os=1; /* $os is 1 for unix */ + $os = 1; /* $os is 1 for unix */ } return $os; } + /** - *@brief shrink the date, make a date shorter for the printing - *@param $p_date format DD.MM.YYYY - *@return date in the format DDMMYY (size = 13 mm in arial 8) + * @brief shrink the date, make a date shorter for the printing + * @param $p_date format DD.MM.YYYY + * @return date in the format DDMMYY (size = 13 mm in arial 8) */ -function shrink_date ($p_date) +function shrink_date($p_date) { - $date=str_replace('.','',$p_date); - $str_date=substr($date,0,4).substr($date,6,2); + $date = str_replace('.', '', $p_date); + $str_date = substr($date, 0, 4) . substr($date, 6, 2); return $str_date; } + /** - *@brief format the date, when taken from the database the format + * @brief format the date, when taken from the database the format * is MM-DD-YYYY - *@param $p_date format YYYY-MM-DD - *@return date in the format DD.MM.YYYY + * @param $p_date format YYYY-MM-DD + * @return date in the format DD.MM.YYYY */ -function format_date ($p_date) +function format_date($p_date) { - $date=explode('-',$p_date); - if ( count($date) != 3) return $p_date; - $str_date=$date[2].'.'.$date[1].'.'.$date[0]; + $date = explode('-', $p_date); + if (count($date) != 3) + return $p_date; + $str_date = $date[2] . '.' . $date[1] . '.' . $date[0]; return $str_date; } /** - *@brief remove the quote or double quote them - *@param $q string - *@return string correctly quoted + * @brief remove the quote or double quote them + * @param $q string + * @return string correctly quoted */ function sql_string($q) { - $ret=str_replace("'","''",$q); + $ret = str_replace("'", "''", $q); return $ret; } + /** - *Should a dialog box that you are disconnected for ajax + * Should a dialog box that you are disconnected for ajax */ function ajax_disconnected($div) { -/** - *if $_SESSION['g_user'] is not set : echo a warning - */ -if ( ! isset($_SESSION['g_user'])) - { - $script='var a=$("'.$div.'");a.style.height="70%";a.style.width="70%";'; - $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;'; - $script=create_script($script); - $html=$script; - $html.=HtmlInput::anchor_close($div); - $html.='<div>'; - $html.=h2('Données non disponibles','class="info" style="width:auto"'); - $html.=h2('Veuillez vous reconnecter',''); - $html.=alert("Déconnecté",true); - $html=escape_xml($html); + /** + * if $_SESSION['g_user'] is not set : echo a warning + */ + if (!isset($_SESSION['g_user'])) + { + $script = 'var a=$("' . $div . '");a.style.height="70%";a.style.width="70%";'; + $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;'; + $script = create_script($script); + $html = $script; + $html.=HtmlInput::anchor_close($div); + $html.='<div>'; + $html.=h2('Données non disponibles', 'class="info" style="width:auto"'); + $html.=h2('Veuillez vous reconnecter', ''); + $html.=alert("Déconnecté", true); + $html = escape_xml($html); - header('Content-type: text/xml; charset=UTF-8'); -echo <<<EOF + header('Content-type: text/xml; charset=UTF-8'); + echo <<<EOF <?xml version="1.0" encoding="UTF-8"?> <data> <ctl>$div</ctl> <code>$html</code> </data> EOF; -exit(); - } + exit(); + } } + /** * * @param int $selected module selected @@ -694,22 +739,29 @@ function show_module($selected) { global $g_user; - $cn=Dossier::connect(); - $amodule=$cn->get_array("select + $cn = Dossier::connect(); + $amodule = $cn->get_array("select me_code,me_menu,me_url from v_all_menu where user_name=$1 and p_type_display='M' - order by p_order",array($g_user->login)); + order by p_order", array($g_user->login)); - if ( $selected != -1 ) + if ($selected != -1) { require_once('template/module.php'); - $file=$cn->get_value("select me_file from v_all_menu where me_code=$1",array($selected)); - if ($file != '') + $file = $cn->get_array("select me_file,me_parameter from v_all_menu + where me_code=$1 and user_name=$2", array($selected,$g_user->login)); + if ($file[0]['me_file'] != '') { - require_once $file; + if ($file[0]['me_parameter'] !== "") + { + // if there are paramter put them in superglobal + $array=compute_variable($file[0]['me_parameter']); + put_global($array); + } + require_once $file[0]['me_file']; exit(); } } @@ -718,82 +770,129 @@ } } +/** + * Find the default module or the first one + * @global $g_user $g_user + * @return default module (string) + */ function find_default_module() { global $g_user; - $cn=Dossier::connect(); + $cn = Dossier::connect(); - $default_module = $cn->get_array("select me_code + $default_module = $cn->get_array("select me_code from profile_menu join profile_user using (p_id) where p_type_display='M' and user_name=$1 and pm_default=1", array($g_user->login)); - if (empty($default_module)) - { - $default_module = $cn->get_array("select me_code + if (empty($default_module)) + { + $default_module = $cn->get_array("select me_code from profile_menu join profile_user using (p_id) where user_name=$1 and p_order=(select min(p_order) from profile_menu - where user_name=$2) limit 1", array($g_user->login,$g_user->login)); - return $default_module[0]['me_code']; - } + where user_name=$2) limit 1", array($g_user->login, $g_user->login)); + return $default_module[0]['me_code']; + } - if (count($default_module) > 1) - { - echo_error("Plusieurs modules sont le module par défaut", __LINE__, __FILE__); - } - elseif (count($default_module) == 1) - { - return $default_module[0]['me_code']; - } + if (count($default_module) > 1) + { + echo_error("Plusieurs modules sont le module par défaut", __LINE__, __FILE__); + } + elseif (count($default_module) == 1) + { + return $default_module[0]['me_code']; + } } /** - * + * show the module + * @global $g_user + * @param $module the $_REQUEST['ac'] exploded into an array + * @param $idx the index */ -function show_menu($module,$idx) +function show_menu($module, $idx) { global $g_user; - $cn=Dossier::connect(); - $amenu=$cn->get_array("select + $cn = Dossier::connect(); + $amenu = $cn->get_array("select me_menu,me_code from v_all_menu where - me_code_dep=$1 and user_name=$2 order by p_order",array($module[$idx],$g_user->login)); + me_code_dep=$1 and user_name=$2 order by p_order", array($module[$idx], $g_user->login)); - if (! empty ($amenu) && count($amenu)>1) + if (!empty($amenu) && count($amenu) > 1) { require 'template/menu.php'; } - elseif (count($amenu)==1) + elseif (count($amenu) == 1) { echo '<div class="topmenu">'; echo h2info($amenu[0]['me_menu']); echo '</div>'; - $module[$idx]=$amenu[0]['me_code']; + $module[$idx] = $amenu[0]['me_code']; } - if (empty($amenu) || count($amenu)==1) + if (empty($amenu) || count($amenu) == 1) { -/** - * @todo add security - * check if user can access this module - */ - $file=$cn->get_value("select me_file + /** + * @todo add security + * check if user can access this module + */ + $file = $cn->get_array("select me_file,me_parameter from menu_ref where me_code=$1 and - (me_file is not null or trim(me_file) <>'')", - array($module[$idx])); + (me_file is not null or trim(me_file) <>'')", array($module[$idx])); - if ( $file != "" ) + if ($file[0]['me_file'] != "") { + if ($file[0]['me_parameter'] !== "") + { + // if there are paramter put them in superglobal + $array=compute_variable($file[0]['me_parameter']); + put_global($array); + } echo '<div class="content">'; - require_once "$file"; + require_once $file[0]['me_file']; echo '</div>'; exit(); } } } +/** + * Put in superglobal (get,post,request) the value contained in + * the superglobal + * @param $array [key] [value] + */ +function put_global($array) +{ + for ($i=0;$i<count($array);$i++) + { + $key=$array[$i]['key']; + $value=$array[$i]['value']; + $_GET[$key]=$value; + $_POST[$key]=$value; + $_REQUEST[$key]=$value; + } +} +/** + * the string has the format a=b&c=d, it is parsed and an array[][key,value] + * is returned + * @param $p_string + * @return $array usable in put_global + */ +function compute_variable($p_string) +{ + $array=array(); + $var=explode("&",$p_string); + for ($i=0;$i < count($var);$i++) + { + $var2=explode('=',$var[$i]); + $array[$i]['key']=$var2[0]; + $array[$i]['value']=$var2[1]; + } + return $array; +} ?> Deleted: phpcompta/trunk/include/ext_inc.php =================================================================== --- phpcompta/trunk/include/ext_inc.php 2011-10-29 01:21:42 UTC (rev 4263) +++ phpcompta/trunk/include/ext_inc.php 2011-10-29 02:36:11 UTC (rev 4264) @@ -1,81 +0,0 @@ -<?php -require_once('class_database.php'); -require_once('class_dossier.php'); -require_once("ac_common.php"); -require_once("constant.php"); -require_once('function_javascript.php'); -require_once('class_extension.php'); -require_once ('class_html_input.php'); -require_once('class_iselect.php'); -require_once ('constant.security.php'); -require_once ('class_user.php'); -echo '<div class="topmenu">'; -@html_page_start($_SESSION['g_theme']); - -$cn=new Database(dossier::id()); -$user=new User($cn); -$user->check(); -$only_plugin=$user->check_dossier(dossier::id()); - - -/* javascript file */ -echo load_all_script(); - -/* show button to return to access */ - -/* show all the extension we can access */ -$a=new ISelect('plugin_code'); -$a->value=Extension::make_array($cn); -$a->selected=(isset($_REQUEST['plugin_code']))?strtoupper($_REQUEST['plugin_code']):''; - -/* no plugin available */ -if ( count($a->value) == 0 ) -{ - alert(j(_("Aucune extension disponible"))); - exit; -} - -/* only one plugin available then we don't propose a choice*/ -if ( count($a->value)==1 ) -{ - $_REQUEST['plugin_code']=$a->value[0]['value']; -} -else -{ - echo '<form method="get" action="do.php">'; - echo Dossier::hidden(); - echo HtmlInput::request_to_hidden(array('plugin_code','ac')); - echo _('Extension').$a->input().HtmlInput::submit('go',_("Choix de l'extension")); - echo '</form>'; - echo '<hr>'; -} -/* if a code has been asked */ -if (isset($_REQUEST['plugin_code']) ) -{ - $cn=new Database(dossier::id()); - $ext=new Extension($cn); - $ext->search('code',$_REQUEST['plugin_code']); - if ( $ext->get_parameter('id') != 0 ) - { - /* security */ - if ( $ext->can_request($_SESSION['g_user']) == 0 ) - { - alert(j(_("Vous ne pouvez pas utiliser cette extension. Contactez votre responsable"))); - exit(); - } - - if ( ! file_exists('../include/ext'.DIRECTORY_SEPARATOR.trim($ext->get_parameter('filepath')))) - { - alert(j(_("Ce fichier n'existe pas "))); - exit(); - } - require_once('ext'.DIRECTORY_SEPARATOR.trim($ext->get_parameter('filepath'))); - } - else - { - alert(j(_("Cette extension n'existe pas "))); - exit(); - } - -} -?> Copied: phpcompta/trunk/include/extension_choice.inc.php (from rev 4263, phpcompta/trunk/include/ext_inc.php) =================================================================== --- phpcompta/trunk/include/extension_choice.inc.php (rev 0) +++ phpcompta/trunk/include/extension_choice.inc.php 2011-10-29 02:36:11 UTC (rev 4264) @@ -0,0 +1,52 @@ +<?php +require_once('class_database.php'); +require_once('class_dossier.php'); +require_once("ac_common.php"); +require_once("constant.php"); +require_once('function_javascript.php'); +require_once('class_extension.php'); +require_once ('class_html_input.php'); +require_once('class_iselect.php'); +require_once ('constant.security.php'); +require_once ('class_user.php'); +echo '<div class="topmenu">'; +@html_page_start($_SESSION['g_theme']); + +$cn=new Database(dossier::id()); +$user=new User($cn); +$user->check(); +$only_plugin=$user->check_dossier(dossier::id()); + + +/* javascript file */ +echo load_all_script(); + +/* show all the extension we can access */ +$a=new ISelect('plugin_code'); +$a->value=Extension::make_array($cn); +$a->selected=(isset($_REQUEST['plugin_code']))?strtoupper($_REQUEST['plugin_code']):''; + +/* no plugin available */ +if ( count($a->value) == 0 ) +{ + alert(j(_("Aucune extension disponible"))); + exit; +} + +/* only one plugin available then we don't propose a choice*/ +if ( count($a->value)==1 ) +{ + $_REQUEST['plugin_code']=$a->value[0]['value']; +} +else +{ + echo '<form method="get" action="do.php">'; + echo Dossier::hidden(); + echo HtmlInput::request_to_hidden(array('plugin_code','ac')); + echo _('Extension').$a->input().HtmlInput::submit('go',_("Choix de l'extension")); + echo '</form>'; + echo '<hr>'; +} +require_once 'extension_get.inc.php'; + +?> Added: phpcompta/trunk/include/extension_get.inc.php =================================================================== --- phpcompta/trunk/include/extension_get.inc.php (rev 0) +++ phpcompta/trunk/include/extension_get.inc.php 2011-10-29 02:36:11 UTC (rev 4264) @@ -0,0 +1,42 @@ +<?php +require_once('class_database.php'); +require_once('class_dossier.php'); +require_once("ac_common.php"); +require_once("constant.php"); +require_once('function_javascript.php'); +require_once('class_extension.php'); +require_once ('class_html_input.php'); +require_once('class_iselect.php'); +require_once ('constant.security.php'); +require_once ('class_user.php'); + +/* if a code has been asked */ +if (isset($_REQUEST['plugin_code']) ) +{ + $cn=new Database(dossier::id()); + $ext=new Extension($cn); + $ext->search('code',$_REQUEST['plugin_code']); + if ( $ext->get_parameter('id') != 0 ) + { + /* security */ + if ( $ext->can_request($_SESSION['g_user']) == 0 ) + { + alert(j(_("Vous ne pouvez pas utiliser cette extension. Contactez votre responsable"))); + exit(); + } + + if ( ! file_exists('../include/ext'.DIRECTORY_SEPARATOR.trim($ext->get_parameter('filepath')))) + { + alert(j(_("Ce fichier n'existe pas "))); + exit(); + } + require_once('ext'.DIRECTORY_SEPARATOR.trim($ext->get_parameter('filepath'))); + } + else + { + alert(j(_("Cette extension n'existe pas "))); + exit(); + } + +} +?> _______________________________________________ Phpcompta-dev mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/phpcompta-dev
