noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
Functions
ac_common.php File Reference

common utilities for a lot of procedure, classe More...

Go to the source code of this file.

Functions

 ajax_disconnected ($div)
 Should a dialog box that you are disconnected for ajax.
 ajax_xml_error ($p_code, $p_string)
 alert ($p_msg, $buffer=false)
 alert in javascript
 cmpDate ($p_date, $p_date_oth)
 Compare 2 dates.
 compute_variable ($p_string)
 the string has the format a=b&c=d, it is parsed and an array[][key,value] is returned
 Decode ($p_html)
 Decode the html for the widegt richtext and remove newline.
 display_dashboard_operation ($p_array, $p_title, $p_div)
 echo_error ($p_log, $p_line="", $p_message="")
 log error into the /tmp/noalyss_error.log it doesn't work on windows
 echo_warning ($p_string)
 warns
 find_default_module ()
 Find the default module or the first one $g_user $g_user.
 format_date ($p_date, $p_from_format= 'YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
 format the date, when taken from the database the format is MM-DD-YYYY
 FormatString ($p_string)
 replaced by sql_string
 get_array_column ($p_array, $key)
 getPeriodeFromMonth ($p_cn, $p_date)
 Return the period corresponding to the date.
 getPeriodeName ($p_cn, $p_id, $pos='p_start')
 Show the periode which found thanks its id.
 h ($p_string)
 to protect again bad characters which can lead to a cross scripting attack the string to be diplayed must be protected
 h1 ($p_string, $p_class="")
 h2 ($p_string, $p_class="", $raw="")
 h2info ($p_string)
 hb ($p_string)
 hi ($p_string)
 html_min_page_start ($p_theme="", $p_script="", $p_script2="")
 Minimal page header for each page, used for small popup window.
 html_page_start ($p_theme="", $p_script="", $p_script2="")
 Default page header for each page.
 html_page_stop ()
 end tag
 isDate ($p_date)
 isNumber (&$p_int)
 j ($p_string)
 escape correctly php string to javascript
 nb ($p_number)
 format the number for the CSV export
 nbm ($p_number)
 format the number with a sep.
 NoAccess ($js=1)
 Echo no access and stop.
 put_global ($array)
 Put in superglobal (get,post,request) the value contained in the parameter field (me_parameter)
 set_language ()
 set the lang thanks the _SESSION['g_lang'] var.
 show_menu ($module, $idx)
 show the module $g_user
 show_module ($selected)
 ShowItem ($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", $default="", $p_extra="")
 /*
 shrink_date ($p_date)
 shrink the date, make a date shorter for the printing
 smaller_date ($p_date)
 shrink the date, make a date shorter for the printing
 span ($p_string, $p_extra='')
 sql_filter_per ($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
 Create the condition to filter on the j_tech_per thanks a from and to date.
 sql_string ($p_string)
 Fix the problem with the quote char for the database.
 td ($p_string='', $p_extra='')
 surround the string with td
 th ($p_string, $p_extra='', $raw='')
 tr ($p_string, $p_extra='')
 what_os ()
 try to determine on what os you are running the pĥpcompte server

Detailed Description

common utilities for a lot of procedure, classe

Definition in file ac_common.php.


Function Documentation

ajax_disconnected ( div)

Should a dialog box that you are disconnected for ajax.

if $_SESSION['g_user'] is not set : echo a warning

Definition at line 770 of file ac_common.php.

{
    /**
     * 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="title" style="width:auto"');
        $html.=h2(_('Veuillez vous reconnecter'), 'class="error"');
        $html.=alert(_("Déconnecté"), true);
        $html = escape_xml($html);

        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();
    }
}
ajax_xml_error ( p_code,
p_string 
)

Definition at line 1040 of file ac_common.php.

{
    $html = escape_xml($p_string);
    header('Content-type: text/xml; charset=UTF-8');
                echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
<code>$p_code</code>
<value>$html</value>
</data>
EOF;
}
alert ( p_msg,
buffer = false 
)

alert in javascript

Parameters:
$p_msgis the message
$bufferif false, echo directly and execute the javascript, if $buffer is true, the alert javascript is in the return string
Returns:
string with alert javascript if $buffer is true

Definition at line 633 of file ac_common.php.

References $r, and j().

Referenced by Fiche_Def\Add(), add_menu(), add_plugin(), add_row(), ajax_error_saldo(), ajax_get_failure(), ajax_misc_failure(), ajaxFid(), anc_refresh_remain(), ask_navigator(), boxsearch_card(), cal(), User\Check(), User\check_dossier(), check_hour(), Extension\check_version(), compute_total_table(), create_menu(), Anc_Group\display_html(), Anc_Acc_List\display_html(), display_periode(), dsp_letter(), encodeJSON(), error_box(), error_compute_ledger(), error_dsp_letter(), error_get_pj(), error_get_predef(), errorFid(), errorPoste(), errorRemoveDoc(), errorRemoveStock(), fill_box(), gestion_add_row(), get_properties(), hide_ledger_choice(), infodiv(), Acc_Ledger_Fin\input(), Document_type\insert(), Todo_List\insert(), Extension\insert_plugin(), js_include(), ledger_add_row(), mod_menu(), mod_plugin(), modify_document_success_box(), modify_menu(), op_save(), popup_select_tva(), profile_show(), Fiche\remove(), remove_action(), remove_bookmark(), Extension\remove_plugin(), result_card_search(), result_poste_search(), result_search_action(), Acc_Parm_Code\save(), save_bookmark(), save_card_category(), User\save_password(), save_periode(), search_action(), search_anc_form(), search_ca(), search_card(), search_letter(), search_operation(), search_poste(), set_action_related(), Document_type\set_number(), set_preference(), set_reconcile(), set_tva_label(), show_bookmark(), show_dbname(), show_fin_chdate(), show_ledger_choice(), show_reconcile(), show_tag(), stock_add_row(), success_box(), success_cat_doc_remove(), success_display_periode(), success_dsp_letter(), success_get_last_date(), success_misc(), success_popup_select_tva(), success_set_tva_label(), success_update_bank(), successFill_ipopcard(), successRemoveComment(), successRemoveDoc(), successRemoveOp(), successRemoveStock(), test(), ICard\test_me(), Acc_Ledger\test_me(), todo_list_show(), todo_list_show_error(), todo_list_show_success(), Document_type\update(), Todo_List\update(), update_card(), update_history_account(), update_history_card(), Extension\update_plugin(), update_predef(), update_row(), Acc_Report\upload(), Menu_Ref\verify(), verify_ca(), and view_action().

{
    $r = '<script language="javascript">';
    $r.= 'alert(\'' . j($p_msg) . '\')';
    $r.= '</script>';

    if ($buffer)
        return $r;
    echo $r;
}
cmpDate ( p_date,
p_date_oth 
)

Compare 2 dates.

Parameters:
p_date
p_date_oth
Returns:
  • == 0 les dates sont identiques
  • > 0 date1 > date2
  • < 0 date1 < date2

Definition at line 170 of file ac_common.php.

References isDate().

Referenced by Fiche\HtmlTable(), Acc_Ledger_Fin\verify(), Acc_Ledger_Sold\verify(), and Acc_Ledger_Purchase\verify().

{
    date_default_timezone_set('Europe/Brussels');

    $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]");
    }
    $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;
}
compute_variable ( p_string)

the string has the format a=b&c=d, it is parsed and an array[][key,value] is returned

Parameters:
$p_string
Returns:
$array usable in put_global

Definition at line 1025 of file ac_common.php.

{
    $array=array();
    if ($p_string == '') return $array;

    $var=explode("&",$p_string);
    if (empty ($var))   return $array;
    for ($i=0;$i < count($var);$i++)
    {
        $var2=explode('=',$var[$i]);
        $array[$i]['key']=$var2[0];
        $array[$i]['value']=$var2[1];
    }
    return $array;
}
Decode ( p_html)

Decode the html for the widegt richtext and remove newline.

Parameters:
$p_htmlstring to decode
Returns:
the html code without new line

Definition at line 574 of file ac_common.php.

{
    $p_html = str_replace('%0D', '', $p_html);
    $p_html = str_replace('%0A', '', $p_html);
    $p_html = urldecode($p_html);
    return $p_html;
}
display_dashboard_operation ( p_array,
p_title,
p_div 
)

Definition at line 1052 of file ac_common.php.

{
        ?>
<div id="<?php echo $p_div;?>" class="inner_box" style="display:none;top:250;left:25%;width: 50%;min-height:50%;overflow:auto;">
        <?php
        echo HtmlInput::title_box($p_title, $p_div, "hide");
        ?>
        <?php if (count($p_array)>0) :?>
        <table class="result">
                <tr>
                        <th><?php echo _('Date')?></th>
                        <th><?php echo _('Code Interne')?></th>
                        <th><?php echo _('Description')?></th>
                        <th>
                                <?php echo _('Montant')?>
                        </th>

                </tr>
                <?php
                        for ($i=0;$i<count($p_array);$i++):
                ?>
                <tr class="<?php echo (($i%2)==0)?'odd':'even';?>">
                        <td>
                                <?php echo smaller_date(format_date($p_array[$i]['jr_date']) );?>
                        </td>
                        <td>
                                <?php echo HtmlInput::detail_op($p_array[$i]['jr_id'], $p_array[$i]['jr_internal']) ?>
                        </td>
                        <td>
                                <?php echo h($p_array[$i]['jr_comment']) ?>
                        </td>
                        <td>
                                <?php echo nbm($p_array[$i]['jr_montant']) ?>
                        </td>
                </tr>
                <?php
                endfor;
                ?>
        </table>
        <?php else: ?>
        <h2 class="notice"><?php echo _('Aucune donnée')?></h2>
        <?php
        endif;
        ?>
</div>
<?php
}
echo_error ( p_log,
p_line = "",
p_message = "" 
)

log error into the /tmp/noalyss_error.log it doesn't work on windows

Parameters:
p_logmessage
p_lineline number
p_messageis the message
Returns:
nothing

Definition at line 148 of file ac_common.php.

References $_ENV, and echo.

Referenced by Dossier\check(), Database\format_name(), Fiche\get_row(), Fiche\get_row_date(), getPeriodeName(), isValid_deprecrated(), Document_modele\Save(), Database\save_upload_document(), sql_filter_per(), and Document_modele\update().

{
    echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
    $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "noalyss_error.log", "a+");
    if ($fdebug != null)
    {
        fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " . $p_message . "\n");
        fclose($fdebug);
    }
}
echo_warning ( p_string)

warns

Parameters:
p_stringerror message gen :
  • none
Returns:
:
  • none

Definition at line 524 of file ac_common.php.

References echo.

Referenced by Document\Generate(), and Dossier\synchro_admin().

{
    echo '<H2 class="error">' . $p_string . "</H2>";
}

Find the default module or the first one $g_user $g_user.

Returns:
default module (string)

Definition at line 861 of file ac_common.php.

{
    global $g_user;
    $cn = Dossier::connect();

    $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));

        /*
         * Try to find the smallest order for module
         */
    if (empty($default_module))
    {
                $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 order by p_order limit 1", array($g_user->login));

                // if no default try to find the default menu
                if ( empty ($default_module))
                {
                        $default_module = $cn->get_array("select me_code
                         from profile_menu join profile_user using (p_id)
                           where
                           p_type_display='E' and
                           user_name=$1 and pm_default=1 ", array($g_user->login));
                        /*
                         * Try to find a default menu by order
                         */
                        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 join profile_user using (p_id)
                                where user_name=$2) limit 1", array($g_user->login, $g_user->login));
                        }

                        /*
                        * if nothing found, there is no profile for this user => exit
                        */
                        if (empty ($default_module))
                        {
                                echo_warning(_("Utilisateur n'a pas de profile, votre administrateur doit en configurer un dans CFGSEC"));
                                exit();
                        }
                }
                return $default_module[0]['me_code'];
    }

    if (count($default_module) > 1)
    {
                // return the first module found
                return $default_module[0]['me_code'];
    }
    elseif (count($default_module) == 1)
    {
        return $default_module[0]['me_code'];
    }
}
format_date ( p_date,
p_from_format = 'YYYY-MM-DD',
p_to_format = 'DD.MM.YYYY' 
)

format the date, when taken from the database the format is MM-DD-YYYY

Parameters:
$p_dateformat
@returndate in the format DD.MM.YYYY

Definition at line 728 of file ac_common.php.

Referenced by Stock\build_tmp_table(), Anticipation\display(), Acc_Account_Ledger\HtmlTable(), Fiche\HtmlTable(), Follow_Up\myList(), and Document\Replace().

{
    if ($p_from_format == 'YYYY-MM-DD')
    {
        $date = explode('-', $p_date);
        if (count($date) != 3)
            return $p_date;
    }
    if ($p_from_format == 'DD.MM.YYYY')
    {
        $temp_date = explode('.', $p_date);
        if (count($temp_date) != 3)
            return $p_date;
        $date[0] = $temp_date[2]; // 0 is year
        $date[1] = $temp_date[1]; // 1 for month
        $date[2] = $temp_date[0]; // 2 for day
    }

    switch ($p_to_format)
    {
        case 'DD.MM.YYYY':
            $str_date = $date[2] . '.' . $date[1] . '.' . $date[0];
            break;
        case 'YYYY-MM-DD':
            $str_date = $date[0] . '-' . $date[1] . '-' . $date[2];
            break;
       case 'YYYYMMDD':
            $str_date = $date[0] . $date[1] . $date[2];
            break;
                 case 'YYYY/MM/DD':
            $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
            break;

                }
    return $str_date;
}
FormatString ( p_string)

replaced by sql_string

Deprecated:

Definition at line 424 of file ac_common.php.

References sql_string().

{
    return sql_string($p_string);
}
get_array_column ( p_array,
key 
)

Definition at line 1099 of file ac_common.php.

{
    $array=array();
    for ($i=0;$i<count($p_array);$i++)
    {
        $r=$p_array[$i];
        if ( isset($r[$key])) {
            $array[]=$r[$key];
        }
    }
    return $array;
}
getPeriodeFromMonth ( p_cn,
p_date 
)

Return the period corresponding to the date.

Parameters:
p_cndatabase connection
p_datethe month + year 'MM.YYYY'
Returns:
: parm_periode.p_id

Definition at line 560 of file ac_common.php.

{
    $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;
    return $R;
}
getPeriodeName ( p_cn,
p_id,
pos = 'p_start' 
)

Show the periode which found thanks its id.

Parameters:
$p_cndatabase connection
p_id
posStart or end
Returns:
: string

Definition at line 540 of file ac_common.php.

References $ret, and echo_error().

{
    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;
}
h ( p_string)
h1 ( p_string,
p_class = "" 
)

Definition at line 70 of file ac_common.php.

{
    return '<h1 ' . $p_class . '>' . htmlspecialchars($p_string) . '</h1>';
}
h2 ( p_string,
p_class = "",
raw = "" 
)

Definition at line 66 of file ac_common.php.

Referenced by Fiche\blank(), Fiche\Display(), Acc_Ledger\display_search_form(), Acc_Ledger_Fin\input(), Default_Menu\test_me(), HtmlInput\title_box(), and Follow_Up\Update().

{
    return '<h2 ' . $p_class . '>' . $raw.htmlspecialchars($p_string) . '</h2>';
}
h2info ( p_string)

Definition at line 61 of file ac_common.php.

Referenced by Anc_Balance_Double\display_html(), Fiche_Attr\test_me(), and Profile_Menu_sql\test_me().

{
    return '<h2 class="info">' . htmlspecialchars($p_string) . '</h2>';
}
hb ( p_string)

Definition at line 51 of file ac_common.php.

Referenced by Acc_Ledger_Sold\confirm(), and Acc_Ledger_Purchase\confirm().

{
    return '<b>' . htmlspecialchars($p_string) . '</b>';
}
hi ( p_string)

Definition at line 46 of file ac_common.php.

{
    return '<i>' . htmlspecialchars($p_string) . '</i>';
}
html_min_page_start ( p_theme = "",
p_script = "",
p_script2 = "" 
)

Minimal page header for each page, used for small popup window.

Parameters:
p_themedefault theme
$p_script
$p_script2another js script
Returns:
none

Definition at line 342 of file ac_common.php.

References $cn, $Res, $s, $style, echo, Database\fetch_array(), and Database\num_row().

{

    $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-classic.css";
        else
        {
            $s = Database::fetch_array($Res, 0);
            $style = $s['the_filestyle'];
        }
    }
    else
    {
        $style = "style-classic.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>';

    echo "<HEAD>
    <TITLE>NOALYSS</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 . "
    <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')
    {
        return;
    }
}
html_page_start ( p_theme = "",
p_script = "",
p_script2 = "" 
)

Default page header for each page.

Parameters:
p_themedefault theme
$p_script
$p_script2another js script Must be called only once
Returns:
none

Definition at line 257 of file ac_common.php.

References $_REQUEST, $cn, $m, $Res, $s, $style, HtmlInput\button_action(), echo, Database\fetch_array(), Database\num_row(), set_language(), and HtmlInput\title_box().

Referenced by Acc_Ledger\test_me().

{
    require_once 'class_html_input.php';
    // check not called twiced
    static  $already_call=0;
    if ( $already_call==1)return;
    $already_call=1;

    $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-classic.css";
        else
        {
            $s = Database::fetch_array($Res, 0);
            $style = $s['the_filestyle'];
        }
    }
    else
    {
        $style = "style-classic.css";
    } // end if
        $title="NOALYSS";

        if ( isset ($_REQUEST['ac'])) {
                if (strpos($_REQUEST['ac'],'/') <> 0)
                {
                        $m=  explode('/',$_REQUEST['ac']);
                        $title=$m[count($m)-1]."  ".$title;
                }
                else
                        $title=$_REQUEST['ac']."  ".$title;
        }
    echo '<!doctype html>';
    echo "<HTML>";

    if ($p_script2 != "")
        $p_script2 = '<script src="' . $p_script2 . '" type="text/javascript"></script>';

    echo "<HEAD>
    <TITLE>$title</TITLE>
        <link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />
    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
    <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
    <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>
    <script language="javascript" src="js/calendar-setup.js"></script>
    <LINK REL="stylesheet" type="text/css" href="calendar-blue.css" media="screen">
    </HEAD>
    ';

    echo "<BODY $p_script>";
    echo '<div id="info_div"></div>';
    echo '<div id="error_div">'.
            HtmlInput::title_box(_("Erreur"), 'error_div','hide').
            '<div id="error_content_div">'.
            '</div>'.
            '<p style="text-align:center">'.
            HtmlInput::button_action('Valider','$(\'error_div\').style.visibility=\'hidden\';$(\'error_content_div\').innerHTML=\'\';').
            '</p>'.
            '</div>';
// language
    if (isset($_SESSION['g_lang']))
    {
                set_language();
    }

}

end tag

Definition at line 392 of file ac_common.php.

References echo.

{
    echo "</BODY>";
    echo "</HTML>";
}
isDate ( p_date)

Definition at line 218 of file ac_common.php.

References trim().

Referenced by Acc_Ledger\build_search_sql(), Todo_List\check(), Anc_Print\check(), cmpDate(), Acc_Ledger_Fin\confirm(), Follow_Up\create_query(), Acc_Reconciliation\filter_date(), Periode\insert(), Acc_Operation\operation_update_date_limit(), Stock_Goods\record_save(), Acc_Ledger\reverse(), Acc_Ledger_Fin\verify(), Acc_Ledger_Purchase\verify(), Acc_Ledger_Sold\verify(), and Todo_List\verify().

{
    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;
    }
    else
    {
        $l_date = explode(".", $p_date);

        if (sizeof($l_date) != 3)
            return null;

        if ($l_date[2] > COMPTA_MAX_YEAR || $l_date[2] < COMPTA_MIN_YEAR)
        {
            return null;
        }

        if (checkdate($l_date[1], $l_date[0], $l_date[2]) == false)
        {
            return null;
        }
    }
    return $p_date;
}
isNumber ( &$  p_int)
j ( p_string)

escape correctly php string to javascript

Definition at line 93 of file ac_common.php.

References $a.

Referenced by action_tag_add(), action_tag_remove(), action_tag_select(), alert(), calendar_zoom(), Document_type\insert(), save_tag(), search_add_tag(), search_clear_tag(), and search_display_tag().

{
    $a = preg_replace("/\r?\n/", "\\n", addslashes($p_string));
    $a = str_replace("'", '\'', $a);
    return $a;
}
nb ( p_number)
nbm ( p_number)
NoAccess ( js = 1)

Echo no access and stop.

Returns:
nothing

Definition at line 404 of file ac_common.php.

References $js, echo, and exit.

Referenced by Stock_Goods\input().

{
    if ($js == 1)
    {
        echo "<script>";
        echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez votre responsable') . "');";
        echo "</script>";
    }
    else
    {
        echo '<div class="redcontent">';
        echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée Contactez votre responsable') . '</h2>';
        echo '</div>';
    }
    exit - 1;
}
put_global ( array)

Put in superglobal (get,post,request) the value contained in the parameter field (me_parameter)

Parameters:
$array[key] [value]

Definition at line 1008 of file ac_common.php.

{
    for ($i=0;$i<count($array);$i++)
    {
        $key=$array[$i]['key'];
        $value=$array[$i]['value'];
        $_GET[$key]=$value;
        $_POST[$key]=$value;
        $_REQUEST[$key]=$value;
    }
}

set the lang thanks the _SESSION['g_lang'] var.

Definition at line 647 of file ac_common.php.

Referenced by html_page_start().

{
    // desactivate local check
    if ( defined("LOCALE") && LOCALE==0 ) return;
    if ( ! isset ($_SESSION['g_lang'])) return;
    $dir = "";
    // set differently the language depending of the operating system
    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');

        return;
    }
    // for windows
    putenv('LANG=' . $_SESSION['g_lang']);
    $dir = setlocale(LC_ALL, $_SESSION['g_lang']);
    bindtextdomain('messages', '.\\lang');
    textdomain('messages');
    bind_textdomain_codeset('messages', 'UTF8');
}
show_menu ( module,
idx 
)

show the module $g_user

Parameters:
$modulethe $_REQUEST['ac'] exploded into an array
$idxthe index of the array : the AD code is splitted into an array thanks the slash

Definition at line 932 of file ac_common.php.

{
    global $g_user;
    $cn = Dossier::connect();
    $amenu = $cn->get_array("select
        me_menu,me_code,me_url,me_javascript,me_type,me_description
        from v_all_menu
        where
        me_code_dep=$1 and user_name=$2 order by p_order", array($module[$idx], $g_user->login));

    if (!empty($amenu) && count($amenu) > 1)
    {
        $a_style_menu=array('topmenu','menu2','menu3');
        if ( $idx > count($a_style_menu))
            $style_menu='menu3';
        else {
            $style_menu=$a_style_menu[$idx];
        }
                require 'template/menu.php';
    }
    elseif (count($amenu) == 1)
    {
                echo '<div class="topmenu">';
                echo h2info($amenu[0]['me_menu']);
                echo '</div>';
                $module[$idx] = $amenu[0]['me_code'];
    }

    if (empty($amenu) || count($amenu) == 1)
    {
                $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type
                from menu_ref
                join profile_menu using (me_code)
                join profile_user using (p_id)
                where
                me_code=$1 and
                user_name=$2 and
                (me_file is not null or trim(me_file) <>'' or
                me_javascript is not null or trim (me_javascript) <> '')", array($module[$idx],$g_user->login));

                if (count($file)==0)
                {
                        echo "Configuration incorrecte pour ce module ".$module[$idx];
                        exit;
                }

                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);
                        }

                        // if file is not a plugin, include the file, otherwise
                        // include the plugin launcher
                        if ( $file[0]['me_type'] != 'PL')
                                require_once $file[0]['me_file'];
                        else
                                require 'extension_get.inc.php';

                        exit();
                }
                if ( $file[0]['me_javascript'] != '')
                {
                    $js=  str_replace('<DOSSIER>', dossier::id(), $file[0]['me_javascript']);
                    echo create_script($js);
                }
    }
}
show_module ( selected)
Parameters:
int$selectedmodule selected

Definition at line 804 of file ac_common.php.

{
    global $g_user;
    $cn = Dossier::connect();
    $amodule = $cn->get_array("select
        me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
        from v_all_menu
        where
        user_name=$1
        and p_type_display='M'
        order by p_order", array($g_user->login));

    if ($selected != -1)
    {
        require_once('template/module.php');
        $file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
            where me_code=$1 and user_name=$2", array($selected,$g_user->login));
        if ( count($file ) == 0 )
        {
                echo '</div>';
                echo '</div>';
                echo '<div class="content">';
                echo_warning(_("Module inexistant")."[ $selected ] ");
                echo '</div>';
                exit();
        }
        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);
            }

                // if file is not a plugin, include the file, otherwise
                // include the plugin launcher
                if ($file[0]['me_type'] != 'PL')
                        {
                                require_once $file[0]['me_file'];
                        }
                        else
                        {
                                // nothing  : direct call to plugin
                        }
        }
        if ( $file[0]['me_javascript'] != '')
        {
                create_script($file[0]['me_javascript']);
        }
    }
}
ShowItem ( p_array,
p_dir = 'V',
class = "mtitle",
class_ref = "mtitle",
default = "",
p_extra = "" 
)

/*

store the string which print the content of p_array in a table used to display the menu

Parameters:
$p_arrayarray like ( 0=>HREF reference, 1=>visible item (name),2=>Help(opt), 3=>selected (opt) 4=>javascript (normally a onclick event) (opt)
$p_dirdirection of the menu (H Horizontal V vertical)
$classCSS for TD tag
$class_refCSS for the A tag
$defaultselected item
$p_extraextra code for the table tag (CSS or javascript)

/*

Returns:
: string

Definition at line 459 of file ac_common.php.

References $all, $class, $href, $p_array, and $ret.

Referenced by MenuAdmin().

{

    $ret = "<TABLE $p_extra>";
    // direction Vertical
    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];

            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')
    {

        $ret.="<TR>";
        foreach ($p_array as $all => $href)
        {
            $title = "";
            $javascript = (isset($href[4])) ? $href[4] : "";

            $set = "A";
            if (isset($href[2]))
                $title = $href[2];

            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>";
    }
    $ret.="</TABLE>";
    return $ret;
}
shrink_date ( p_date)

shrink the date, make a date shorter for the printing

Parameters:
$p_dateformat DD.MM.YYYY
Returns:
date in the format DDMMYY (size = 13 mm in arial 8)

Definition at line 704 of file ac_common.php.

{
    $date = str_replace('.', '', $p_date);
    $str_date = substr($date, 0, 4) . substr($date, 6, 2);
    return $str_date;
}
smaller_date ( p_date)

shrink the date, make a date shorter for the printing

Parameters:
$p_dateformat DD.MM.YYYY
Returns:
date in the format DDMMYY (size = 13 mm in arial 8)

Definition at line 715 of file ac_common.php.

Referenced by Follow_Up\myList().

{
    $str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
    return $str_date;
}
span ( p_string,
p_extra = '' 
)

Definition at line 41 of file ac_common.php.

{
    return '<span ' . $p_extra . '>' . $p_string . '</span>';
}
sql_filter_per ( p_cn,
p_from,
p_to,
p_form = 'p_id',
p_field = 'jr_tech_per' 
)

Create the condition to filter on the j_tech_per thanks a from and to date.

Parameters:
$p_cndatabase conx
$p_fromstart date (date)
$p_toend date (date)
$p_formif the p_from and p_to are date or p_id
$p_fieldcolumn name
Returns:
a string containg the query

Definition at line 592 of file ac_common.php.

References $periode, $pPeriode, echo_error(), and exit.

Referenced by Anc_Operation\get_balance(), Acc_Account_Ledger\get_row(), Acc_Ledger\get_row(), Fiche\get_row(), Acc_Ledger\get_rowSimple(), Acc_Ledger\get_solde(), Impress\parse_formula(), Acc_Bilan\verify(), and Acc_Bilan\warning().

{

    if ($p_form != 'p_id' &&
            $p_form != 'date')
    {
        echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
        exit(-1);
    }
    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__ . sprintf(_('Attention periode 
                     non trouvee periode p_from= %s p_to_periode = %s'), $p_from ,
                    $p_to));


        $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')) ";
    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')) ";
    return $periode;
}
sql_string ( p_string)

Fix the problem with the quote char for the database.

Parameters:
$p_string
Returns:
a string which won't let strange char for the database

Definition at line 435 of file ac_common.php.

References trim().

Referenced by Anc_Plan\add(), Fiche_Def\Add(), Acc_Account_Ledger\belong_ledger(), Acc_Ledger\build_search_sql(), Fiche\build_sql(), Fiche\count_by_modele(), Follow_Up\create_query(), Stock\create_query_histo(), Phpcompta_SQL\delete(), Follow_Up\filter_by_tag(), FormatString(), Anc_Account\get_by_name(), User\get_ledger(), Pre_operation_detail\get_operation(), Acc_Ledger_Sold\insert(), Acc_Ledger_Purchase\insert(), Acc_Ledger_Fin\insert(), Fiche\insert(), Acc_Ledger_Purchase\insert_no_deductible(), Acc_Parm_Code\save(), Fiche_Def\save_class_base(), Fiche_Def\SaveLabel(), HtmlInput\select_stock(), contact\Summary(), Fiche\Summary(), Anc_Plan\update(), and Fiche\update().

{
    $p_string = trim($p_string);
    if (strlen($p_string) == 0)
        return null;
    $p_string = str_replace("'", "''", $p_string);
    $p_string = str_replace('\\', '\\\\', $p_string);
    return $p_string;
}
td ( p_string = '',
p_extra = '' 
)
th ( p_string,
p_extra = '',
raw = '' 
)
tr ( p_string,
p_extra = '' 
)
what_os ( )

try to determine on what os you are running the pĥpcompte server

Returns:
0 it is a windows 1 it is a Unix like

Definition at line 684 of file ac_common.php.

{
    $inc_path = get_include_path();

    if (strpos($inc_path, ";") != 0)
    {
        $os = 0;   /* $os is 0 for windoz */
    }
    else
    {
        $os = 1;   /* $os is 1 for unix */
    }
    return $os;
}
 All Data Structures Namespaces Files Functions Variables Enumerations