";
}
-/*!
+
+/* !
* \brief Show the periode which found thanks its id
*
*
@@ -471,17 +504,17 @@ function echo_warning($p_string)
*
* \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 @@ function getPeriodeName($p_cn,$p_id,$pos='p_start')
* \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 @@ function Decode($p_html)
* \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= '';
- 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 ''.$_SESSION['g_lang'].' domaine non supporté';
- }
- 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 '' . $_SESSION['g_lang'] . ' domaine non supporté';
+ }
+ 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);
- return $str_date;
-}
-/**
- *@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
- */
-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 = str_replace('.', '', $p_date);
+ $str_date = substr($date, 0, 4) . substr($date, 6, 2);
return $str_date;
}
/**
- *@brief remove the quote or double quote them
- *@param $q string
- *@return string correctly quoted
+ * @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
+ */
+function format_date($p_date)
+{
+ $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
*/
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.='
';
- $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.='
';
+ $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 <<$div$html
EOF;
-exit();
- }
+ exit();
+ }
}
+
/**
*
* @param int $selected module selected
@@ -694,22 +739,29 @@ exit();
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 @@ function show_module($selected)
}
}
+/**
+ * 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 '
';
echo h2info($amenu[0]['me_menu']);
echo '
';
- $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 '