/**
* LetterBox Class
*
* Contains all the specific functions of Maarch LetterBox
*
* @package Maarch LetterBox 2.4
* @version 2.1
* @since 06/2007
* @license GPL
* @author Claire Figueras
* @author Loic Vinet
*/
class LetterBox extends dbquery
{
/**
*
* @access private
* @var integer
*/
private $the_start;
/**
* Redefinition of the LetterBox object constructor
*/
function __construct()
{
// configure the sql argument order by
if(isset($_GET['start']))
{
$this->the_start = strip_tags($_GET['start']);
}
else
{
$this->the_start = 0;
}
}
/**
* Configure the sql argument order by
*
*/
public function define_order()
{
// configure the sql argument order by
$orderby = "";
if(isset($_GET['order']))
{
if($_GET['order'] == "arrivdesc")
{
$orderby = "order by CREATION_DATE desc";
}
elseif($_GET['order'] == "arrivasc")
{
$orderby = "order by CREATION_DATE asc";
}
if($_GET['order'] == "datedesc")
{
$orderby = "order by CREATION_DATE desc";
}
elseif($_GET['order'] == "dateasc")
{
$orderby = "order by CREATION_DATE asc";
}
if($_GET['order'] == "typedesc")
{
$orderby = "order by TYPE_ID desc";
}
elseif($_GET['order'] == "typeasc")
{
$orderby = "order by TYPE_ID asc";
}
if($_GET['order'] == "limdesc")
{
$orderby = "order by CUSTOM_D2 desc";
}
elseif($_GET['order'] == "limasc")
{
$orderby = "order by CUSTOM_D2 asc";
}
if($_GET['order'] == "expdesc")
{
$orderby = "order by AUTHOR desc";
}
elseif($_GET['order'] == "expasc")
{
$orderby = "order by AUTHOR asc";
}
if($_GET['order'] == "statusdesc")
{
$orderby = "order by AUTHOR desc";
}
elseif($_GET['order'] == "statusasc")
{
$orderby = "order by AUTHOR asc";
}
if($_GET['order'] == "residdesc")
{
$orderby = "order by RES_ID desc";
}
elseif($_GET['order'] == "residasc")
{
$orderby = "order by RES_ID asc";
}
if($_GET['order'] == "residdesc_copy")
{
$orderby = "order by r.RES_ID desc";
}
elseif($_GET['order'] == "residasc_copy")
{
$orderby = "order by r.RES_ID asc";
}
if($_GET['order'] == "objdesc")
{
$orderby = "order by DESCRIPTION desc";
}
elseif($_GET['order'] == "objasc")
{
$orderby = "order by DESCRIPTION asc";
}
if($_GET['order'] == "destdesc")
{
$orderby = "order by DEST_USER desc";
}
elseif($_GET['order'] == "destasc")
{
$orderby = "order by DEST_USER asc";
}
if($_GET['order'] == "limdesc")
{
$orderby = "order by CUSTOM_D2 desc";
}
elseif($_GET['order'] == "limasc")
{
$orderby = "order by CUSTOM_D2 asc";
}
if($_GET['order'] == "priodesc")
{
$orderby = "order by PRIORITY desc";
}
elseif($_GET['order'] == "prioasc")
{
$orderby = "order by PRIORITY asc";
}
if($_GET['order'] == "servdesc")
{
$orderby = "order by DESTINATION desc";
}
elseif($_GET['order'] == "servasc")
{
$orderby = "order by DESTINATION asc";
}
if($_GET['order'] == "socidesc")
{
$orderby = "order by SOCIETE desc";
}
elseif($_GET['order'] == "sociasc")
{
$orderby = "order by SOCIETE asc";
}
if($_GET['order'] == "vieweddesc")
{
$orderby = "order by VIEWED desc";
}
elseif($_GET['order'] == "viewedasc")
{
$orderby = "order by VIEWED asc";
}
}
return $orderby;
}
/**
* Show the list of mail to validate
*
* @param array $listarr array which contains all the data to show
* @param int $nb_total number of element to show
* @param string $title list title
* @param string $name page name
*/
public function validate_list($listarr, $nb_total, $title, $name)
{
$_SESSION['diff'] = array();
//$_SESSION['resultat'] = "";
$_SESSION['error'] = '';
// show the document list in result of the search
$page_list1 = "";
$page_list2 = "";
//require_once("class_functions.php");
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more than 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '";
}
?>
}
/**
* Show the list of mail to postindex
*
* @param array $listarr array which contains all the data to show
* @param int $nb_total number of element to show
* @param string $title list title
* @param string $name page name
*/
public function qualif_list($listarr, $nb_total, $title, $name)
{
$_SESSION['diff'] = array();
//$_SESSION['resultat'] = "";
$_SESSION['error'] = '';
// show the document list in result of the search
$page_list1 = "";
$page_list2 = "";
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more than 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '";
}
$this->connect();
?>
}
/**
* Build the alphabetic list of departments letters
*
* @param string $page page name
*/
public function servicelistletters($page = "liste")
{
// List all the alphabet letter to view the doc types who are starting with the letter
if(isset($_GET['show']))
{
if($_GET['show'] == "false")
{
$show = "&show=false";
}
else
{
$show = "";
}
}
else
{
$show = "";
}
?>
connect();
$this->query("select count(*) as total from ".$table_name." where ENABLED = 'Y' ".$where);
$nb_total_1 = $this->fetch_object();
$nb_total = $nb_total_1->total;
// define the defaults values
$nb_pages = ceil($nb_total/$nb_show);
$link = "index.php?page=".$page_name."&start=".$this->the_start."&order=".$this->orderby.$what;
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '';
$page_list2 .= $previous." ".$next.'
';
}
}
$this->query("select distinct ID from ".$table_name." where ENABLED = 'Y' ".$where." order by ID asc limit ".$this->the_start.",".$nb_show);
echo ' '.$title.'
';
$this->servicelistletters();
echo $page_list1;
?>
echo _ID.' '._DEPARTMENT;?>
echo _DESC;?>
echo _ADD_DEPARTMENT;?>
echo _ADD_DEPARTMENT;?>
connect();
$color = "line1";
while($line = $this->fetch_object())
{
if($color == ' class="col"')
{
$color = '';
}
else
{
$color = ' class="col"';
}
$db->query("select ID, SERVICE from ".$table_name." where ID ='".$line->ID."'");
$desc = "";
$line2 = $db->fetch_object();
$desc = $line2->SERVICE;
?>
>
ID; ?>
echo _DELETE;?>
clearserviceinfos();
}
/**
* Draw the departments list
*
* @param string $where sorting of the list (empty by default)
* @param string $what first letter of the name (empty by default)
*/
public function emetlist($where = "",$what = "")
{
// draw the services list
$func = new functions();
/* Configuration */
$title = _SHIPPER_LIST;
$page_name = "emet";
$table_name = $_SESSION['tablename']['senders'];
$res_table = $_SESSION['ressources'][0]['tablename'];
$nb_show = $_SESSION['config']['nblinetoshow'];
if(!empty($what))
{
$what = "&what=".$what;
}
/***********************/
$this->connect();
$this->query("select count(*) as total from ".$table_name." where (1=1) and (TOCONTACT <> 'EXT' or TOCONTACT is null) ".$where);
//$this->show();
$nb_total_1 = $this->fetch_object();
$nb_total = $nb_total_1->total;
// define the defaults values
$nb_pages = ceil($nb_total/$nb_show);
$link = "index.php?page=".$page_name."&start=".$this->the_start."&order=".$this->orderby.$what;
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($this->the_start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($this->the_start > 0)
{
$start_prev = $this->the_start - $nb_show;
$previous = ''._PREVIOUS.' ';
}
if($this->the_start <> $lastpage)
{
$start_next = $this->the_start + $nb_show;
$next = ''._NEXT.' ';
}
$page_list1 = $page_list1." ";
$page_list2 = $page_list2."
";
if($previous <> '' || $next <> '')
{
if(empty($previous)) { $previous = " "; }
if(empty($next)) { $next = " "; }
$page_list1 .= $previous." ".$next.'
';
$page_list2 .= $previous." ".$next.'';
}
}
$this->query("select distinct ID from ".$table_name." where (1=1) and (TOCONTACT <> 'EXT' or TOCONTACT is null) ".$where." order by ID asc limit ".$this->the_start.",".$nb_show);
echo ' '.$title.'
';
$this->emetlistletters();
echo $page_list1;
?>
echo _LASTNAME;?>
echo _FIRSTNAME;?>
echo _SOCIETY;?>
echo _ADD_SHIPPER;?>
echo _ADD_SHIPPER;?>
connect();
$color = "line1";
while($line = $this->fetch_object())
{
if($color == ' class="col"')
{
$color = '';
}
else
{
$color = ' class="col"';
}
$db->query("select ID, LASTNAME, FIRSTNAME, SOCIETY from ".$table_name." where ID ='".$line->ID."'");
$desc = "";
$line2 = $db->fetch_object();
$name = $line2->LASTNAME;
$prenom = $line2->FIRSTNAME;
$societe = $line2->SOCIETY;
?>
>
'));" > echo _DELETE;?>
clearemetinfos();
}
/**
* Draw the senders list
*
* @param string $where sorting of the list (empty by default)
* @param string $what first letter of the name (empty by default)
*/
public function senderlist($where = "",$what = "")
{
// draw the services list
$func = new functions();
/* Configuration */
$title = _SENDER_LIST;
$page_name = "sender";
$table_name = $_SESSION['tablename']['senders'];
$res_table = $_SESSION['ressources'][0]['tablename'];
$nb_show = $_SESSION['config']['nblinetoshow'];
if(!empty($what))
{
$what = "&what=".$what;
}
/***********************/
$this->connect();
$this->query("select count(*) as total from ".$table_name." where (1=1) ".$where);
//$this->show();
$nb_total_1 = $this->fetch_object();
$nb_total = $nb_total_1->total;
// define the defaults values
$nb_pages = ceil($nb_total/$nb_show);
$link = "index.php?page=".$page_name."&start=".$this->the_start."&order=".$this->orderby.$what;
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($this->the_start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($this->the_start > 0)
{
$start_prev = $this->the_start - $nb_show;
$previous = ''._PREVIOUS.' ';
}
if($this->the_start <> $lastpage)
{
$start_next = $this->the_start + $nb_show;
$next = ''._NEXT.' ';
}
$page_list1 = $page_list1." ";
$page_list2 = $page_list2."
";
if($previous <> '' || $next <> '')
{
if(empty($previous)) { $previous = " "; }
if(empty($next)) { $next = " "; }
$page_list1 .= $previous." ".$next.'
';
$page_list2 .= $previous." ".$next.'';
}
}
$this->query("select distinct ID from ".$table_name." where (1=1) and TOCONTACT = 'EXT' ".$where." order by ID asc limit ".$this->the_start.",".$nb_show);
echo ' '.$title.'
';
$this->senderlistletters();
echo $page_list1;
?>
echo _LASTNAME;?>
echo _FIRSTNAME;?>
echo _SOCIETY;?>
echo _ADD_SENDER;?>
echo _ADD_SENDER;?>
connect();
$color = "line1";
while($line = $this->fetch_object())
{
if($color == ' class="col"')
{
$color = '';
}
else
{
$color = ' class="col"';
}
$db->query("select ID, LASTNAME, FIRSTNAME, SOCIETY from ".$table_name." where ID ='".$line->ID."'");
$desc = "";
$line2 = $db->fetch_object();
$name = $line2->LASTNAME;
$prenom = $line2->FIRSTNAME;
$societe = $line2->SOCIETY;
?>
>
'));" > echo _DELETE;?>
clearsenderinfos();
}
/**
* Load the data of the letterbox.xml file into session
*
*/
public function xmltosessionletterbox()
{
$xmlfile = simplexml_load_file('xml/letterbox.xml') ;
$_SESSION['civilite'] = array();
//$_SESSION['emetteur'] = array();
$_SESSION['nature'] = array();
$_SESSION['quartiers'] = array();
$increment = 0;
foreach($xmlfile->CIVILITE as $CIVILITE)
{
foreach($CIVILITE-> CIV as $CIV)
{
$_SESSION['civilite'][$increment] = utf8_decode((string) $CIV);
$increment++;
}
}
$increment = 0;
foreach($xmlfile->NATURE as $NATURE)
{
foreach($NATURE-> NAT as $NAT)
{
$_SESSION['nature'][$increment] = utf8_decode((string) $NAT);
$increment++;
}
}
$increment = 0;
foreach($xmlfile->QUARTIERS as $QUARTIERS)
{
foreach($QUARTIERS->QUA as $QUA)
{
$_SESSION['quartiers'][$increment] = utf8_decode((string) $QUA);
$increment++;
}
}
}
/**
* Load the rights on the departments in the database (used in the class_usergroups.php file)
*
*/
public function load_group_service()
{
if(count($_SESSION['services_choisis']) > 0)
{
$where = " DESTINATION IN ( ";
for($i=0; $i < count($_SESSION['services_choisis']); $i++)
{
$where .= " \'".trim($_SESSION['services_choisis'][$i])."\', ";
}
$where = ereg_replace(", $", " )", $where);
}
else
{
$where = " (1=-1) ";
}
$this->connect();
$this->query("DELETE FROM ".$_SESSION['tablename']['security'] ." where GROUP_ID = '".$_SESSION['m_admin']['groups']['GroupId']."'");
$this->query("INSERT INTO ".$_SESSION['tablename']['security']." VALUES ('".$_SESSION['m_admin']['groups']['GroupId']."', '".$_SESSION['ressources'][0]['tablename']."', '".$where."', '', 'N' , 'N')");
}
/**
* List of the mail process basket documents
*
* @param array $listarr contains the document index of the process basket
* @param int $nb_total number of document
* @param string $title title
* @param string $name page name
*/
public function mail_process($listarr, $nb_total, $title, $name)
{
$_SESSION['diff'] = array();
$_SESSION['error'] = '';
// show the document list in result of the search
$page_list1 = "";
$page_list2 = "";
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more than 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($start > 0)
{
$start_prev = $start - $nb_show;
$previous = "< "._PREVIOUS." ";
}
if($start <> $lastpage)
{
$start_next = $start + $nb_show;
$next = " "._NEXT." >";
}
$page_list1 = $page_list1." ".$previous." ".$next."
";
$page_list2 = $page_list2." ".$previous." ".$next."
";
}
?>
echo $title; ?>
echo _CLICK_LINE_PROCESS;?>
}
/**
* List of the mail process basket documents
*
* @param array $listarr contains the document index of the process basket
* @param int $nb_total number of document
* @param string $title title
* @param string $name page name
*/
public function ending_process($listarr, $nb_total, $title, $name)
{
$_SESSION['diff'] = array();
$_SESSION['error'] = '';
// show the document list in result of the search
$page_list1 = "";
$page_list2 = "";
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more than 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($start > 0)
{
$start_prev = $start - $nb_show;
$previous = "< "._PREVIOUS." ";
}
if($start <> $lastpage)
{
$start_next = $start + $nb_show;
$next = " "._NEXT." >";
}
$page_list1 = $page_list1." ".$previous." ".$next."
";
$page_list2 = $page_list2." ".$previous." ".$next."
";
}
?>
echo $title; ?>
echo _CLICK_LINE_PROCESS;?>
if(!$_SESSION['current_basket']['no_action'])
{
?>
} ?>
}
/**
* Form to modify a department
*
* @param $string $mode up or add
* @param int $id $id of the department to change
*/
public function formservice($mode,$id = "")
{
$func = new functions();
$state = true;
if(!isset($_SESSION['m_admin']['services']))
{
$this->clearserviceinfos();
}
if( $mode <> "add" && empty($_SESSION['error']))
{
$this->connect();
$this->query("select * from ".$_SESSION['tablename']['services']." where ID = '".$id."'");
if($this->nb_result() == 0)
{
$_SESSION['error'] = _DEPARTMENT.' '._ALREADY_EXISTS;
$state = false;
}
else
{
$_SESSION['m_admin']['services'] = array();
$line = $this->fetch_object();
$_SESSION['m_admin']['services']['ID'] = $line->ID;
$_SESSION['m_admin']['services']['LABEL'] = $line->SERVICE;
$_SESSION['m_admin']['services']['VALIDATE'] = $line->ENABLED;
$_SESSION['m_admin']['services']['listmodel'] = array();
$this->query("select SEQUENCE, USER_ID from ".$_SESSION['tablename']['listmodel']." where RES_TABLE = 'res_x' and ID = '".$_SESSION['m_admin']['services']['ID']."' order by SEQUENCE asc ");
while($line = $this->fetch_object())
{
$_SESSION['m_admin']['services']['listmodel'][$line->SEQUENCE -1]['USER_ID'] = $line->USER_ID;
}
for($i=0; $i < count($_SESSION['m_admin']['services']['listmodel']); $i++)
{
$this->query("SELECT FIRSTNAME, LASTNAME, DEPARTMENT, MAIL FROM ".$_SESSION['tablename']['users']." WHERE USER_ID='".$_SESSION['m_admin']['services']['listmodel'][ $i]['USER_ID']."'");
//$this->show();
$line = $this->fetch_object();
$_SESSION['m_admin']['services']['listmodel'][$i]['FIRSTNAME'] = $line->FIRSTNAME;
$_SESSION['m_admin']['services']['listmodel'][$i]['LASTNAME'] = $line->LASTNAME;
$_SESSION['m_admin']['services']['listmodel'][$i]['DEPARTMENT'] = $line->DEPARTMENT;
$_SESSION['m_admin']['services']['listmodel'][$i]['MAIL'] = $line->MAIL;
}
}
}
?>
wash($_REQUEST['name'], "no", _THE_LASTNAME.' ');
if(isset($_REQUEST['prenom']) && !empty($_REQUEST['prenom']))
{
$_SESSION['m_admin']['emet']['PRENOM'] = $func->wash($_REQUEST['prenom'], "no", _THE_FIRSTNAME.' ');
}
$_SESSION['m_admin']['emet']['FONCTION'] = '';
if(isset($_REQUEST['fonction']) && !empty($_REQUEST['fonction']))
{
$_SESSION['m_admin']['emet']['FONCTION'] = $func->wash($_REQUEST['fonction'], "no", _THE_FUNCTION.' ');
}
if ($_REQUEST['societe'] <> '')
{
$_SESSION['m_admin']['emet']['SOCIETE'] = $func->wash($_REQUEST['societe'], "no", _THE_SOCIETY." ");
}
else
{
$_SESSION['m_admin']['emet']['SOCIETE'] = '';
}
if ($_REQUEST['street'] <> '')
{
$_SESSION['m_admin']['emet']['STREET'] = $func->wash($_REQUEST['street'], "no", _ADDRESS.' ');
}
else
{
$_SESSION['m_admin']['emet']['STREET'] = '';
}
if ($_REQUEST['town'] <> '')
{
$_SESSION['m_admin']['emet']['TOWN'] = $func->wash($_REQUEST['town'], "no", _TOWN.' ');
}
else
{
$_SESSION['m_admin']['emet']['TOWN'] = '';
}
if ($_REQUEST['cp'] <> '')
{
$_SESSION['m_admin']['emet']['CP'] = $func->wash($_REQUEST['cp'], "no", _POSTAL_CODE.' ');
}
else
{
$_SESSION['m_admin']['emet']['CP'] = '';
}
if ($_REQUEST['phone'] <> '')
{
$_SESSION['m_admin']['emet']['PHONE'] = $func->wash($_REQUEST['phone'], "num", _PHONE." ");
}
else
{
$_SESSION['m_admin']['emet']['PHONE'] = '';
}
if ($_REQUEST['mail'] <> '')
{
$_SESSION['m_admin']['emet']['MAIL'] = $func->wash($_REQUEST['mail'], "mail", _MAIL);
}
else
{
$_SESSION['m_admin']['emet']['MAIL'] = '';
}
/* if ($_REQUEST['tocontact'] <> '')
{
$_SESSION['m_admin']['emet']['TOCONTACT'] = $func->wash($_REQUEST['tocontact'], "no", "Contact privilegi�");
}
else
{
$_SESSION['m_admin']['emet']['TOCONTACT'] = '';
}*/
}
/**
* Return the user information in sessions vars
*
* @param string $mode add or up
*/
public function senderinfo($mode)
{
require_once("class_usergroup_content.php");
// return the user information in sessions vars
$func = new functions();
$_SESSION['m_admin']['sender']['NAME'] = $func->wash($_REQUEST['name'], "no", _THE_LASTNAME.' ');
if(isset($_REQUEST['prenom']) && !empty($_REQUEST['prenom']))
{
$_SESSION['m_admin']['sender']['PRENOM'] = $func->wash($_REQUEST['prenom'], "no", _THE_FIRSTNAME.' ');
}
$_SESSION['m_admin']['sender']['FONCTION'] = '';
if(isset($_REQUEST['fonction']) && !empty($_REQUEST['fonction']))
{
$_SESSION['m_admin']['sender']['FONCTION'] = $func->wash($_REQUEST['fonction'], "no", _THE_FUNCTION.' ');
}
if ($_REQUEST['societe'] <> '')
{
$_SESSION['m_admin']['sender']['SOCIETE'] = $func->wash($_REQUEST['societe'], "no", _THE_SOCIETY." ");
}
else
{
$_SESSION['m_admin']['sender']['SOCIETE'] = '';
}
if ($_REQUEST['street'] <> '')
{
$_SESSION['m_admin']['sender']['STREET'] = $func->wash($_REQUEST['street'], "no", _ADDRESS.' ');
}
else
{
$_SESSION['m_admin']['sender']['STREET'] = '';
}
if ($_REQUEST['town'] <> '')
{
$_SESSION['m_admin']['sender']['TOWN'] = $func->wash($_REQUEST['town'], "no", _TOWN.' ');
}
else
{
$_SESSION['m_admin']['sender']['TOWN'] = '';
}
if ($_REQUEST['cp'] <> '')
{
$_SESSION['m_admin']['sender']['CP'] = $func->wash($_REQUEST['cp'], "no", _POSTAL_CODE.' ');
}
else
{
$_SESSION['m_admin']['sender']['CP'] = '';
}
if ($_REQUEST['phone'] <> '')
{
$_SESSION['m_admin']['sender']['PHONE'] = $func->wash($_REQUEST['phone'], "num", _PHONE." ");
}
else
{
$_SESSION['m_admin']['sender']['PHONE'] = '';
}
if ($_REQUEST['mail'] <> '')
{
$_SESSION['m_admin']['sender']['MAIL'] = $func->wash($_REQUEST['mail'], "mail", _MAIL);
}
else
{
$_SESSION['m_admin']['sender']['MAIL'] = '';
}
}
/**
* Add ou modify emett in the database
*
* @param string $mode up or add
*/
public function addupemet($mode)
{
// add ou modify users in the database
$this->emetinfo($mode);
if(!empty($_SESSION['error']))
{
if($mode == "up")
{
if(!empty($_SESSION['m_admin']['emet']['ID']))
{
header("location: index.php?page=emet_up&id=".$_SESSION['m_admin']['emet']['ID']);
exit;
}
else
{
header("location: index.php?page=emet");
exit;
}
}
if($mode == "add")
{
header("location: index.php?page=emet_add");
exit;
}
}
else
{
$this->connect();
if($mode == "add")
{
$this->query("INSERT INTO `".$_SESSION['tablename']['senders']."` ( LASTNAME , FIRSTNAME , SOCIETY, FUNCTION , STREET, TOWN, CP, PHONE, MAIL ) VALUES ( '".$_SESSION['m_admin']['emet']['NAME']."', '".$_SESSION['m_admin']['emet']['PRENOM']."', '".$_SESSION['m_admin']['emet']['SOCIETE']."', '".$_SESSION['m_admin']['emet']['FONCTION']."', '".$_SESSION['m_admin']['emet']['STREET']."', '".$_SESSION['m_admin']['emet']['TOWN']."', '".$_SESSION['m_admin']['emet']['CP']."', '".$_SESSION['m_admin']['emet']['PHONE']."', '".$_SESSION['m_admin']['emet']['MAIL']."' )");
$this->clearemetinfos();
$_SESSION['error'] = _SHIPPER_ADDED;
header("location: index.php?page=emet");
exit;
}
elseif($mode == "up")
{
$this->query("update `".$_SESSION['tablename']['senders']."` set `LASTNAME` = '".$_SESSION['m_admin']['emet']['NAME']."', `FIRSTNAME` = '".$_SESSION['m_admin']['emet']['PRENOM']."', `FUNCTION` = '".$_SESSION['m_admin']['emet']['FONCTION']."', `SOCIETY` = '".$_SESSION['m_admin']['emet']['SOCIETE']."', `STREET` = '".$_SESSION['m_admin']['emet']['STREET']."', `TOWN` = '".$_SESSION['m_admin']['emet']['TOWN']."', `CP` = '".$_SESSION['m_admin']['emet']['CP']."' , `PHONE` = '".$_SESSION['m_admin']['emet']['PHONE']."', `MAIL` = '".$_SESSION['m_admin']['emet']['MAIL']."' where ID = '".$_SESSION['m_admin']['emet']['ID']."'");
$this->clearemetinfos();
$_SESSION['error'] = _SHIPPER_UPDATED;
header("location: index.php?page=emet");
exit;
}
}
}
/**
* Add ou modify a sender in the database
*
* @param string $mode up or add
*/
public function addupsender($mode)
{
// add ou modify users in the database
$this->senderinfo($mode);
if(!empty($_SESSION['error']))
{
if($mode == "up")
{
if(!empty($_SESSION['m_admin']['sender']['ID']))
{
header("location: index.php?page=sender_up&id=".$_SESSION['m_admin']['sender']['ID']);
exit;
}
else
{
header("location: index.php?page=sender");
exit;
}
}
if($mode == "add")
{
header("location: index.php?page=sender_add");
exit;
}
}
else
{
$this->connect();
if($mode == "add")
{
$this->query("INSERT INTO `".$_SESSION['tablename']['senders']."` ( LASTNAME , FIRSTNAME , SOCIETY, FUNCTION , STREET, TOWN, CP, PHONE, MAIL, TOCONTACT ) VALUES ( '".$_SESSION['m_admin']['sender']['NAME']."', '".$_SESSION['m_admin']['sender']['PRENOM']."', '".$_SESSION['m_admin']['sender']['SOCIETE']."', '".$_SESSION['m_admin']['sender']['FONCTION']."', '".$_SESSION['m_admin']['sender']['STREET']."', '".$_SESSION['m_admin']['sender']['TOWN']."', '".$_SESSION['m_admin']['sender']['CP']."', '".$_SESSION['m_admin']['sender']['PHONE']."', '".$_SESSION['m_admin']['sender']['MAIL']."' , 'EXT' )");
$this->clearsenderinfos();
$_SESSION['error'] = _SENDER_ADDED;
header("location: index.php?page=sender");
exit;
}
elseif($mode == "up")
{
$this->query("update `".$_SESSION['tablename']['senders']."` set `LASTNAME` = '".$_SESSION['m_admin']['sender']['NAME']."', `FIRSTNAME` = '".$_SESSION['m_admin']['sender']['PRENOM']."', `FUNCTION` = '".$_SESSION['m_admin']['sender']['FONCTION']."', `SOCIETY` = '".$_SESSION['m_admin']['sender']['SOCIETE']."', `STREET` = '".$_SESSION['m_admin']['sender']['STREET']."', `TOWN` = '".$_SESSION['m_admin']['sender']['TOWN']."', `CP` = '".$_SESSION['m_admin']['sender']['CP']."' , `PHONE` = '".$_SESSION['m_admin']['sender']['PHONE']."', `MAIL` = '".$_SESSION['m_admin']['sender']['MAIL']."', `TOCONTACT` = 'EXT' where ID = '".$_SESSION['m_admin']['sender']['ID']."'");
$this->clearsenderinfos();
$_SESSION['error'] = _SENDER_UPDATED;
header("location: index.php?page=sender");
exit;
}
}
}
/**
* Form to modify a emettor
*
* @param $string $mode up or add
* @param int $id $id of the department to change
*/
public function formemet($mode,$id = "")
{
$func = new functions();
$state = true;
if(!isset($_SESSION['m_admin']['emet']))
{
$this->clearemetinfos();
}
if( $mode <> "add" && empty($_SESSION['error']))
{
$this->connect();
$this->query("select * from ".$_SESSION['tablename']['senders']." where ID = '".$id."'");
if($this->nb_result() == 0)
{
$_SESSION['error'] = _THE_SHIPPER.' '._ALREADY_EXISTS;
$state = false;
}
else
{
$_SESSION['m_admin']['emet'] = array();
$line = $this->fetch_object();
$_SESSION['m_admin']['emet']['ID'] = $line->ID;
$_SESSION['m_admin']['emet']['NAME'] = $line->LASTNAME;
$_SESSION['m_admin']['emet']['PRENOM'] = $line->FIRSTNAME;
$_SESSION['m_admin']['emet']['SOCIETE'] = $line->SOCIETY;
$_SESSION['m_admin']['emet']['FONCTION'] = $line->FUNCTION;
$_SESSION['m_admin']['emet']['STREET'] = $line->STREET;
$_SESSION['m_admin']['emet']['TOWN'] = $line->TOWN;
$_SESSION['m_admin']['emet']['CP'] = $line->CP;
$_SESSION['m_admin']['emet']['PHONE'] = $line->PHONE;
$_SESSION['m_admin']['emet']['MAIL'] = $line->MAIL;
$_SESSION['m_admin']['emet']['TOCONTACT'] = $line->TOCONTACT;
}
}
?>
clearsenderinfos();
}
if( $mode <> "add" && empty($_SESSION['error']))
{
$this->connect();
$this->query("select * from ".$_SESSION['tablename']['senders']." where ID = '".$id."'");
if($this->nb_result() == 0)
{
$_SESSION['error'] = _THE_SENDER.' '._ALREADY_EXISTS;
$state = false;
}
else
{
$_SESSION['m_admin']['sender'] = array();
$line = $this->fetch_object();
$_SESSION['m_admin']['sender']['ID'] = $line->ID;
$_SESSION['m_admin']['sender']['NAME'] = $line->LASTNAME;
$_SESSION['m_admin']['sender']['PRENOM'] = $line->FIRSTNAME;
$_SESSION['m_admin']['sender']['SOCIETE'] = $line->SOCIETY;
$_SESSION['m_admin']['sender']['FONCTION'] = $line->FUNCTION;
$_SESSION['m_admin']['sender']['STREET'] = $line->STREET;
$_SESSION['m_admin']['sender']['TOWN'] = $line->TOWN;
$_SESSION['m_admin']['sender']['CP'] = $line->CP;
$_SESSION['m_admin']['sender']['PHONE'] = $line->PHONE;
$_SESSION['m_admin']['sender']['MAIL'] = $line->MAIL;
$_SESSION['m_admin']['sender']['TOCONTACT'] = $line->TOCONTACT;
}
}
?>
";
}
$_SESSION['m_admin']['services']['LABEL'] = $func->wash($_REQUEST['label'], "no", _THE_WORDING);
$_SESSION['m_admin']['services']['ID'] = $func->wash($_REQUEST['id'], "no", _ID);
}
/**
* Update or insert trhe database with the department info
*/
public function upservices()
{
$this->servicesinfo();
if(!empty($_SESSION['error']))
{
if($_REQUEST['mode'] == "up")
{
if(!empty($_SESSION['m_admin']['services']['ID']))
{
header("location: index.php?page=service_up&id=".$_SESSION['m_admin']['services']['ID']);
exit;
}
else
{
header("location: index.php?page=liste");
exit;
}
}
elseif($_REQUEST['mode'] == "add" )
{
header("location: index.php?page=service_add");
exit;
}
}
else
{
$this->connect();
if( $_REQUEST['mode'] <> "add")
{
$this->query("update `".$_SESSION['tablename']['services']."` set `SERVICE` = '".addslashes($_SESSION['m_admin']['services']['LABEL'])."' , `ENABLED` = 'Y' where ID = '".$_SESSION['m_admin']['services']['ID']."'");
$this->query("Delete from ".$_SESSION['tablename']['listmodel']." where RES_TABLE ='res_x' and ID = '".$_SESSION['m_admin']['services']['ID']."'");
for($i=0; $i < count($_SESSION['m_admin']['services']['listmodel']);$i++)
{
$seq = $i+1;
$this->query("insert into ".$_SESSION['tablename']['listmodel']." ( RES_TABLE , ID, SEQUENCE, USER_ID ) VALUES ('res_x', '".$_SESSION['m_admin']['services']['ID']."', ".$seq.", '".$_SESSION['m_admin']['services']['listmodel'][ $i]['USER_ID']."')");
}
if($_REQUEST['mode'] == "up")
{
$_SESSION['error'] = _DEPARTMENT_MODIF;
if($_SESSION['history']['servicesup'] == "true")
{
require("class_history.php");
$users = new history();
$users->add($_SESSION['tablename']['services'], $_SESSION['m_admin']['services']['ID'],"UP",_DEPARTMENT_MODIF." : ".$_SESSION['m_admin']['services']['LABEL']);
}
}
$this->clearserviceinfos();
header("location: index.php?page=liste");
exit;
}
else
{
$this->query("select ID from `".$_SESSION['tablename']['services']."` where ID = '".$_SESSION['m_admin']['services']['ID']."'");
if($this->nb_result() > 0)
{
$_SESSION['error'] = _THE_DEPARTMENT.' '.$_SESSION['m_admin']['services']['ID'].' '._ALREADY_EXISTS;
header("location: index.php?page=service_add&show=false");
exit;
}
else
{
require("class_history.php");
$users = new history();
if( $_REQUEST['mode'] == "add")
{
$this->query("INSERT INTO `".$_SESSION['tablename']['services']."` ( `ID` , `SERVICE`,`ENABLED` ) VALUES ('".$_SESSION['m_admin']['services']['ID']."', '".$_SESSION['m_admin']['services']['LABEL']."','Y')");
if($_SESSION['history']['servicesadd'] == "true")
{
$users->add($_SESSION['tablename']['services'], $_SESSION['m_admin']['services']['ID'],"ADD", _DEPARTMENT_ADDED." : ".$_SESSION['m_admin']['services']['LABEL']);
}
}
$this->query("Delete from ".$_SESSION['tablename']['listmodel']." where RES_TABLE ='res_x' and ID = '".$_SESSION['m_admin']['services']['ID']."'");
for($i=0; $i < count($_SESSION['m_admin']['services']['listmodel']);$i++)
{
$seq = $i+1;
$this->query("insert into ".$_SESSION['tablename']['listmodel']." ( RES_TABLE , ID, SEQUENCE, USER_ID ) VALUES ('res_x', '".$_SESSION['m_admin']['services']['ID']."', ".$seq.", '".$_SESSION['m_admin']['services']['listmodel'][ $i]['USER_ID']."')");
}
$_SESSION['error'] = _DEPARTMENT_ADDED;
}
$_SESSION['error'] = "";
}
if ($_REQUEST['mode'] == "add")
{
$url = "index.php?page=liste";
}
$this->clearserviceinfos();
header("location: ".$url);
exit;
}
}
/**
* List of the mail in copy
*
* @param array $listarr contains the document index of the mail in copy
* @param int $nb_total number of document
* @param string $title title
* @param string $name page name
*/
public function list_copy_mail($listarr, $nb_total, $title,$name )
{
$page_list1 = "";
$page_list2 = "";
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($start == $next_start)
{
$page_list1 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($start > 0)
{
$start_prev = $start - $nb_show;
$previous = "< ";
}
if($start <> $lastpage)
{
$start_next = $start + $nb_show;
$next = " "._NEXT." >";
}
$page_list1 = $page_list1." ".$previous." ".$next."
";
}
?>
echo $title; ?>
";
}
/**
* List of the mail in the autorized departments
*
* @param array $listarr contains the document index
* @param int $nb_total number of document
* @param string $title title
* @param string $name page name
*/
public function dep_mail_list($listarr, $nb_total, $title, $service, $status )
{
$page_list1 = "";
$page_list2 = "";
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "dep_result.php";
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($start > 0)
{
$start_prev = $start - $nb_show;
$previous = "< "._PREVIOUS." ";
}
if($start <> $lastpage)
{
$start_next = $start + $nb_show;
$next = " "._NEXT." >";
}
$page_list1 = $page_list1." ".$previous." ".$next."
";
$page_list2 = $page_list2." ".$previous." ".$next."
";
}
//exit();
?>
echo $_SESSION['error']; $_SESSION['error'] = ""; ?>
echo $title; ?>
}
/**
* Alphabetical list of the models
*
* @param string $page page name
*/
public function modelslistletters($page = "models")
{
// List all the alphabet letter to view the doc types who are starting with the letter
if(isset($_GET['show']))
{
if($_GET['show'] == "false")
{
$show = "&show=false";
}
else
{
$show = "";
}
}
else
{
$show = "";
}
?>
} ?>
:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
- echo _ALL_DEPARTMENTS;?>
connect();
$this->query("select count(*) as total from ".$table_name." ".$where);
$nb_total_1 = $this->fetch_object();
$nb_total = $nb_total_1->total;
// define the defaults values
$nb_pages = ceil($nb_total/$nb_show);
$link = "index.php?page=".$page_name."&start=".$this->the_start."&order=".$this->orderby.$what;
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($this->the_start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($this->the_start > 0)
{
$start_prev = $this->the_start - $nb_show;
$previous = ''._PREVIOUS.' ';
}
if($this->the_start <> $lastpage)
{
$start_next = $this->the_start + $nb_show;
$next = ''._NEXT.' ';
}
$page_list1 = $page_list1." ";
$page_list2 = $page_list2."
";
if($previous <> '' || $next <> '')
{
if(empty($previous)) { $previous = " "; }
if(empty($next)) { $next = " "; }
$page_list1 .= $previous." ".$next.'
';
$page_list2 .= $previous." ".$next.'';
}
}
$this->query("select distinct ID from ".$table_name." ".$where." order by label asc limit ".$this->the_start.",".$nb_show);
echo ' '.$title.'
';
$this->modelslistletters();
echo $page_list1;
?>
echo _WORDING;?>
echo _DESC;?>
echo _ADD_MODEL;?>
echo _ADD_MODEL;?>
connect();
$color = "line1";
while($line = $this->fetch_object())
{
if($color == ' class="col"')
{
$color = '';
}
else
{
$color = ' class="col"';
}
$db->query("select ID, LABEL, COMMENT from ".$table_name." where ID ='".$line->ID."'");
$desc = "";
$line2 = $db->fetch_object();
$desc = $line2->LABEL;
$comment = $line2->COMMENT;
?>
>
'));" > echo _DELETE;?>
clearmodelinfos();
$_SESSION['services'] = array();
$this->query("select ID, SERVICE from ".$_SESSION['tablename']['services']." where ENABLED = 'Y'");
while($line = $this->fetch_object())
{
array_push($_SESSION['services'], array("ID"=>$line->ID, "LABEL" => $line->SERVICE));
}
$_SESSION['chosen_services'] = array();
}
/**
* Clear the session variables of the model administration
*
*/
private function clearmodelinfos()
{
// clear the session variable for the models
$_SESSION['m_admin']['model'] = array();
$_SESSION['m_admin']['model']['ID'] = "";
$_SESSION['m_admin']['model']['LABEL'] = "";
$_SESSION['m_admin']['model']['COMMENT'] = "";
$_SESSION['m_admin']['model']['DATE'] = "";
$_SESSION['m_admin']['model']['CONTENT'] = "";
$_SESSION['m_admin']['model']['SERVICES'] = array();
}
/**
* Form to add or modify a model
*
* @param string $mode up or add
* @param string $id identifier of the model to modify
*/
public function formmodel($mode,$id = "")
{
$func = new functions();
$state = true;
if(!isset($_SESSION['m_admin']['model']))
{
$this->clearmodelinfos();
}
if( $mode <> "add" && empty($_SESSION['error']))
{
$this->connect();
$this->query("select * from ".$_SESSION['tablename']['models']." where ID = '".$id."'");
if($this->nb_result() == 0)
{
$_SESSION['error'] = _MODEL.' '._UNKNOWN;
$state = false;
}
else
{
$_SESSION['m_admin']['model'] = array();
$line = $this->fetch_object();
$_SESSION['m_admin']['model']['ID'] = $line->ID;
$_SESSION['m_admin']['model']['LABEL'] = trim($line->LABEL);
$_SESSION['m_admin']['model']['COMMENT'] = trim($line->COMMENT);
$_SESSION['m_admin']['model']['DATE'] = $line->CREATION_DATE;
$_SESSION['m_admin']['model']['CONTENT'] = stripslashes($line->CONTENT);
//$_SESSION['m_admin']['model']['CONTENT'] = str_replace("\'", "'",$line->CONTENT);
//$_SESSION['m_admin']['model']['CONTENT'] = str_replace('\"', '"' ,$line->CONTENT);
//$_SESSION['m_admin']['model']['CONTENT'] = $line->CONTENT;
$_SESSION['m_admin']['model']['SERVICES'] = array();
$this->query("select s.ID, s.SERVICE from ".$_SESSION['tablename']['model_service']." ms, ".$_SESSION['tablename']['services']." s where ms.ID_MODEL = ".$_SESSION['m_admin']['model']['ID']." and s.ID = ms.ID_SERVICE");
//$this->show();
while($res = $this->fetch_object())
{
array_push($_SESSION['m_admin']['model']['SERVICES'] , array('ID' =>$res->ID, 'LABEL' => $res->SERVICE));
}
}
}
?>
";
}
$allowedTags=' ';
$allowedTags.='';
if($_REQUEST['model_content']!='')
{
$_SESSION['m_admin']['model']['CONTENT'] = strip_tags(addslashes(trim($_REQUEST['model_content'])),$allowedTags);
}
else
{
$_SESSION['m_admin']['model']['CONTENT'] = '';
//$_SESSION['error'] .= _MODEL_EMPTY.". ";
}
$_SESSION['m_admin']['model']['LABEL'] = $func->wash($_REQUEST['model_name'], "no", _THE_WORDING);
$_SESSION['m_admin']['model']['LABEL'] = trim(stripslashes($_SESSION['m_admin']['model']['LABEL']));
$_SESSION['m_admin']['model']['COMMENT'] = "";
if(!empty($_REQUEST['model_comment']) && isset($_REQUEST['model_comment']))
{
$_SESSION['m_admin']['model']['COMMENT'] = trim(stripslashes($_REQUEST['model_comment']));
}
if($_REQUEST['mode'] == "up")
{
$_SESSION['m_admin']['model']['ID'] = $func->wash($_REQUEST['model_id'], "no", _ID);
}
//if(count($_SESSION['m_admin']['model']['SERVICES']) < 1)
//{
// $_SESSION['error'] .= _ATTACH_MODEL_TO_DEP.". ";
//}
}
/**
* Update the database with the model data
*
*/
public function upmodel()
{
$this->modelinfo();
if(!empty($_SESSION['error']))
{
if($_REQUEST['mode'] == "up")
{
if(!empty($_SESSION['m_admin']['model']['ID']))
{
header("location: index.php?page=model_up&id=".$_SESSION['m_admin']['label']['ID']);
exit;
}
else
{
header("location: index.php?page=models");
exit;
}
}
elseif($_REQUEST['mode'] == "add" )
{
header("location: index.php?page=model_add");
exit;
}
}
else
{
$this->connect();
if( $_REQUEST['mode'] <> "add")
{
$this->query("update `".$_SESSION['tablename']['models']."` set LABEL = '".addslashes($_SESSION['m_admin']['model']['LABEL'])."' , COMMENT = '".addslashes($_SESSION['m_admin']['model']['COMMENT'])."', CONTENT = '".$_SESSION['m_admin']['model']['CONTENT']."' where ID = '".$_SESSION['m_admin']['model']['ID']."'");
$this->query("Delete from ".$_SESSION['tablename']['model_service']." where ID_MODEL = '".$_SESSION['m_admin']['model']['ID']."'");
for($i=0; $i < count($_SESSION['m_admin']['model']['SERVICES']);$i++)
{
$this->query("insert into ".$_SESSION['tablename']['model_service']." ( ID_SERVICE, ID_MODEL ) VALUES ( '".$_SESSION['m_admin']['model']['SERVICES'][$i]['ID']."', ".$_SESSION['m_admin']['model']['ID'].")");
}
if($_REQUEST['mode'] == "up")
{
$_SESSION['error'] = _MODEL_MODIFICATION;
if($_SESSION['history']['modelsup'] == "true")
{
require("class_history.php");
$users = new history();
$users->add($_SESSION['tablename']['models'], $_SESSION['m_admin']['model']['ID'],"UP",_MODEL_MODIFICATION." : ".$_SESSION['m_admin']['model']['LABEL']);
}
}
$this->clearmodelinfos();
header("location: index.php?page=models");
exit;
}
else
{
$this->query("select LABEL from ".$_SESSION['tablename']['models']." where LABEL = '".addslashes($_SESSION['m_admin']['model']['LABEL'])."'");
if($this->nb_result() > 0)
{
$_SESSION['error'] = _THE_MODEL.' '.$_SESSION['m_admin']['model']['LABEL'].' '._ALREADY_EXISTS;
header("location: index.php?page=model_add");
exit;
}
else
{
require("class_history.php");
$users = new history();
if( $_REQUEST['mode'] == "add")
{
$this->query("INSERT INTO ".$_SESSION['tablename']['models']." ( LABEL, CREATION_DATE, COMMENT, CONTENT ) VALUES ( '".addslashes($_SESSION['m_admin']['model']['LABEL'])."', now(),'".addslashes($_SESSION['m_admin']['model']['COMMENT'])."', '".$_SESSION['m_admin']['model']['CONTENT']."')");
$this->query("select ID from ".$_SESSION['tablename']['models']." where LABEL = '".addslashes($_SESSION['m_admin']['model']['LABEL'])."' and COMMENT = '".addslashes($_SESSION['m_admin']['model']['COMMENT'])."' and CONTENT = '".$_SESSION['m_admin']['model']['CONTENT']."'");
$res = $this->fetch_object();
$_SESSION['m_admin']['model']['ID'] = $res->ID;
if($_SESSION['history']['modelsadd'] == "true")
{
$users->add($_SESSION['tablename']['models'], $_SESSION['m_admin']['model']['ID'],"ADD", _MODEL_ADDED." : ".$_SESSION['m_admin']['model']['LABEL']);
}
}
// $this->query("Delete from ".$_SESSION['tablename']['model_service']." where ID = ".$_SESSION['m_admin']['model']['ID']);
for($i=0; $i < count($_SESSION['m_admin']['model']['SERVICES']);$i++)
{
$this->query("insert into ".$_SESSION['tablename']['model_service']." (ID_MODEL, ID_SERVICE ) VALUES (".$_SESSION['m_admin']['model']['ID'].", '".$_SESSION['m_admin']['model']['SERVICES'][$i]['ID']."' )");
}
$_SESSION['error'] = _MODEL_ADDED;
}
$_SESSION['error'] = "";
}
if ($_REQUEST['mode'] == "add")
{
$url = "index.php?page=models";
}
$this->clearmodelinfos();
header("location: ".$url);
exit;
}
}
/**
* replace the defined fields in the instance of the model
*
* @param string $content model content
*/
public function fields_replace($content)
{
$content = str_replace("[REF_COURRIER]", $_SESSION['courrier']['identifier'], $content);
$content = str_replace("[NO_AFFAIRE]", $_SESSION['courrier']['res_id'], $content);
$content = str_replace("[CIV_EMETTEUR]", $_SESSION['courrier']['civ'], $content);
$content = str_replace("[NOM_EMETTEUR]", $_SESSION['courrier']['author'], $content);
$content = str_replace("[PRENOM_EMETTEUR]", $_SESSION['courrier']['prenom'], $content);
$content = str_replace("[SOCIETE_EMETTEUR]", $_SESSION['courrier']['societe'], $content);
$content = str_replace("[OBJET]", $_SESSION['courrier']['description'], $content);
$content = str_replace("[TYPE]", $_SESSION['courrier']['type_id'], $content);
$content = str_replace("[DATE_LIM]", $_SESSION['courrier']['date_limite'], $content);
$content = str_replace("[DATE_ARRIVEE]", $_SESSION['courrier']['date_arrivee'], $content);
$content = str_replace("[NATURE]", $_SESSION['courrier']['nature'], $content);
$this->query("select SERVICE from ".$_SESSION['tablename']['services']." where ID = '".$_SESSION['courrier']['service']."'");
$res = $this->fetch_object();
$content = str_replace("[SERVICE]", $res->SERVICE, $content);
$content = str_replace("[NEW_EMETTEUR]", $_SESSION['user']['FirstName'].' '.$_SESSION['user']['LastName'], $content);
$content = str_replace("[PHONE_EMETTEUR]", $_SESSION['user']['Phone'], $content);
$content = str_replace("[MAIL_EMETTEUR]", $_SESSION['user']['Mail'], $content);
$content = str_replace("[DEP_EMETTEUR]", $_SESSION['user']['department'], $content);
$content = str_replace("[REP_COURRIER_SIMPLE]", $_SESSION['courrier']['rep_courrier_simple'], $content);
$content = str_replace("[REP_DIRECT]", $_SESSION['courrier']['rep_direct'], $content);
$content = str_replace("[REP_MAIL]", $_SESSION['courrier']['rep_mail'], $content);
$content = str_replace("[REP_AR]", $_SESSION['courrier']['rep_AR'], $content);
$content = str_replace("[REP_FAX]", $_SESSION['courrier']['rep_fax'], $content);
$content = str_replace("[REP_AUTRE]", $_SESSION['courrier']['rep_autre'], $content);
$content = str_replace("[NOTES_TRAIT]", $_SESSION['courrier']['notes'], $content);
$content = str_replace("[QUALITE]", $_SESSION['courrier']['qualite'], $content);
$content = str_replace("[NUM_RUE]", $_SESSION['courrier']['num_rue'], $content);
$content = str_replace("[RUE]", $_SESSION['courrier']['rue'], $content);
$content = str_replace("[VILLE]", $_SESSION['courrier']['ville'], $content);
$content = str_replace("[CODE_POSTAL]", $_SESSION['courrier']['code'], $content);
$content = str_replace("[DATE_TODAY]", date("d-m-Y"), $content);
return $content;
}
/**
* delete a model in the database
*
* @param string $id model identifier
*/
public function delmodel($id)
{
if(!empty($_SESSION['error']))
{
header("location: index.php?page=models");
exit;
}
else
{
$this->connect();
$this->query("select ID, LABEL from ".$_SESSION['tablename']['models']." where ID = ".$id);
if($this->nb_result() == 0)
{
$_SESSION['error'] = _MODEL.' '._UNKNOWN;
header("location: index.php?page=models");
exit;
}
else
{
$res = $this->fetch_object();
$label = $res->LABEL;
$this->query("delete from ".$_SESSION['tablename']['models']." where ID = ".$id);
$this->query("delete from ".$_SESSION['tablename']['model_service']." where ID_MODEL = ".$id);
if($_SESSION['history']['modelsdel'])
{
require("class_history.php");
$users = new history();
$users->add($_SESSION['tablename']['models'], $id,"DEL",_MODEL_DELETION." : ".$label);
}
$_SESSION['error'] = _DELETED_MODEL;
header("location: index.php?page=models");
exit;
}
}
}
/**
* delete a model in the database
*
* @param string $id model identifier
*/
public function delemet($id)
{
if(!empty($_SESSION['error']))
{
header("location: index.php?page=emet");
exit;
}
else
{
$this->connect();
$this->query("select ID from ".$_SESSION['tablename']['senders']." where ID = ".$id);
if($this->nb_result() == 0)
{
$_SESSION['error'] = _SHIPPER.' '._UNKNOWN;
header("location: index.php?page=emet");
exit;
}
else
{
$res = $this->fetch_object();
$label = $res->LABEL;
$this->query("delete from ".$_SESSION['tablename']['senders']." where ID = ".$id);
$_SESSION['error'] = _SHIPPER." ".strtolower(_DELETED);
header("location: index.php?page=emet");
exit;
}
}
}
/**
* delete a model in the database
*
* @param string $id model identifier
*/
public function delsender($id)
{
if(!empty($_SESSION['error']))
{
header("location: index.php?page=sender");
exit;
}
else
{
$this->connect();
$this->query("select ID from ".$_SESSION['tablename']['senders']." where ID = ".$id);
if($this->nb_result() == 0)
{
$_SESSION['error'] = _SENDER.' '._UNKNOWN;
header("location: index.php?page=sender");
exit;
}
else
{
$res = $this->fetch_object();
$label = $res->LABEL;
$this->query("delete from ".$_SESSION['tablename']['senders']." where ID = ".$id);
$_SESSION['error'] = _SENDER." ".strtolower(_DELETED);
header("location: index.php?page=sender");
exit;
}
}
}
/**
* List of the out mail basket
*
* @param array $listarr contains the document index of the out basket
* @param int $nb_total number of document
* @param string $title title
* @param string $name page name
*/
public function mail_out($listarr, $nb_total, $title, $name)
{
$_SESSION['diff'] = array();
$_SESSION['error'] = '';
// show the document list in result of the search
$page_list1 = "";
$page_list2 = "";
$func = new functions();
if(isset($_REQUEST['start']))
{
$start = strip_tags($_REQUEST['start']);
}
else
{
$start = 0;
}
if(isset($_GET['order']))
{
$orderby = strip_tags($_GET['order']);
}
else
{
$orderby = 0;
}
$link = "index.php?page=".$name;
// define the defaults values
$nb_show = $_SESSION['config']['nblinetoshow'];
$nb_pages = ceil($nb_total/$nb_show);
// if they are more than 1 page we do pagination with 2 forms
if($nb_pages > 1)
{
$next_start = 0;
$page_list1 = '
'._GO_TO_PAGE.'
';
$page_list2 = '
'._GO_TO_PAGE.'
';
$lastpage = 0;
for($i = 0;$i <> $nb_pages; $i++)
{
$page_name = $i + 1;
$the_line = $i + 1;
if($start == $next_start)
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
else
{
$page_list1 .= "".$the_line." ";
$page_list2 .= "".$the_line." ";
}
$next_start = $next_start + $nb_show;
$lastpage = $next_start;
}
$lastpage = $lastpage - $nb_show;
$previous = "";
$next = "";
if($start > 0)
{
$start_prev = $start - $nb_show;
$previous = "< "._PREVIOUS." ";
}
if($start <> $lastpage)
{
$start_next = $start + $nb_show;
$next = " "._NEXT." >";
}
$page_list1 = $page_list1." ".$previous." ".$next."
";
$page_list2 = $page_list2." ".$previous." ".$next."
";
}
?>
echo $title; ?>
if(!$_SESSION['current_basket']['no_action'])
{
?>
} ?>
}
public function manage_list($res_id, $user_id)
{
$this->query("select * from ".$_SESSION['tablename']['listinstance']." where res_id = ".$res_id);
if($this->nb_result() < 1)
{
$this->query("insert into ".$_SESSION['tablename']['listinstance']." (res_table, res_id, sequence, user_id) values ('res_x', ".$res_id.", 1, '".$user_id."')");
//$this->show();
}
else
{
$this->query("update ".$_SESSION['tablename']['listinstance']." set user_id = '".$user_id."' where res_id = ".$res_id." and res_table = 'res_x' and sequence = 1");
//$this->show();
}
//exit();
}
/**
* delete a note in the database
*
* @param string $id note identifier
*/
public function delnote($id, $resid)
{
if(!empty($_SESSION['error']))
{
?>
exit;
}
else
{
$this->connect();
$this->query("select ID from ".$_SESSION['tablename']['notes']." where ID = ".$id." and USER_ID = '".$_SESSION['user']['UserId']."'");
if($this->nb_result() == 0)
{
$_SESSION['error'] = _CANT_DELETE_NOTE;
header("location: index.php?page=details&id=".$resid);
exit;
}
else
{
$res = $this->fetch_object();
$label = $res->LABEL;
$this->query("delete from ".$_SESSION['tablename']['notes']." where ID = ".$id);
//Mise � jour de l'historique
if($_SESSION['history']['notesdel'])
{
require_once("class_history.php");
$hist = new history();
$hist->add($_SESSION['tablechoice'], $resid ,"DEL", _DELETION_NOTE);
}
header("location: notes_courrier.php?id=".$resid);
exit;
}
}
}
public function increment_viewed_var($res_table, $res_id, $user_id)
{
if(!empty($res_table) && !empty($res_id) && !empty($user_id))
{
$this->connect();
$this->query("select viewed from ".$_SESSION['tablename']['listinstance']." where res_table ='".$res_table."' and res_id = ".$res_id." and user_id = '".$user_id."'");
if($this->nb_result() == 0)
{
return false;
}
else
{
$res = $this->fetch_object();
$viewed = $res->viewed;
$viewed = (int) $viewed + 1;
$this->query("update ".$_SESSION['tablename']['listinstance']." set viewed = ".$viewed." where res_table ='".$res_table."' and res_id = ".$res_id." and user_id = '".$user_id."'");
//$this->show();
return true;
}
}
else
{
return false;
}
}
public function test_reserved_time($res_id, $res_table, $status)
{
if($status <> 'RSV')
{
return $status;
}
else
{
$this->connect();
$this->query("select value from ".$_SESSION['tablename']['param']." where key1 = '".$res_table."' and key2 = '".$res_id."' and id = 'affaire_reservee'");
$res = $this->fetch_object();
$timestamp = $res->value;
// Reserved time expired
if( ($timestamp - mktime( date("H") , date("i") , date("s") , date("m") , date("d") , date("Y"))) < 0 )
{
$this->query("update ".$res_table." set status = 'ATT', dest_user = '' where res_id = ".$res_id);
return 'ATT';
}
// Reserved time not yet expired
else
{
return 'RSV';
}
}
}
}
?>