*/
class Models extends dbquery
{
private $the_start;
private $models_styles_xml_path = "xml/models_styles.xml";
/**
* 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;
}
}
public function getModelsStyles()
{
$xmlModelsStyles = simplexml_load_file($this->models_styles_xml_path);
if ($xmlModelsStyles) {
$xmlModelsStyles = $this->object2array($xmlModelsStyles);
} else {
return _NO_MODEL_STYLE;
}
return $xmlModelsStyles;
}
/**
* 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 = "";
}
?>
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 = '';
$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;
//updated by lgi for oo_generate
?>
ID |
|
|
|
|
connect();
$color = "line1";
while ($line = $this->fetch_object()) {
if ($color == ' class="col"') {
$color = '';
} else {
$color = ' class="col"';
}
//updated by lgi for oo_generate
$db->query("select ID, LABEL, COMMENT from ".$table_name." where ID ='".$line->ID."'");
$desc = "";
$line2 = $db->fetch_object();
$idmodel = $line2->ID;
$desc = $line2->LABEL;
$comment = $line2->COMMENT;
?>
>
|
|
|
|
'));" >
|
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']['TYPE'] = "";
$_SESSION['m_admin']['model']['STYLE'] = "";
$_SESSION['m_admin']['model']['SERVICES'] = array();
$_SESSION['admin_models'] = 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();
$modelsStyles = $this->getModelsStyles();
require_once("class_webdav_tools.php");
//added by lgi for webdav_ws.php
$_SESSION['admin_models'] = array();
$_SESSION['admin_models']['model_id'] = 'base_1';
$webdav = new webdav_tools();
$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['admin_models']['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']['TYPE'] = $line->TYPE;
$_SESSION['m_admin']['model']['STYLE'] = $line->STYLE;
$_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['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']));
}
$_SESSION['m_admin']['model']['TYPE'] = $func->wash($_REQUEST['model_type'], "no", _THE_TYPE);
if ($_REQUEST['model_type'] == 'ODT') {
$_SESSION['m_admin']['model']['STYLE'] = $func->wash($_REQUEST['model_style'], "no", _THE_STYLE);
} else {
$_SESSION['m_admin']['model']['STYLE'] = 0;
}
if ($_REQUEST['mode'] == "up") {
$_SESSION['m_admin']['model']['ID'] = $func->wash($_REQUEST['model_id'], "no", _ID);
}
if (!$_SESSION['admin_models']['on_progress'] && $_REQUEST['model_type'] == 'ODT' && $_REQUEST['mode'] == 'add') {
$_SESSION['error'] .= _YOU_MUST_EDIT_THE_MODEL;
}
}
/**
* 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']."', TYPE = '".$_SESSION['m_admin']['model']['TYPE']."', STYLE = ".$_SESSION['m_admin']['model']['STYLE']." 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;$iquery("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_once("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_once("class_history.php");
$users = new history();
if ($_REQUEST['mode'] == "add") {
$this->query("INSERT INTO ".$_SESSION['tablename']['models']." (LABEL, CREATION_DATE, COMMENT, CONTENT, TYPE, STYLE) VALUES ('".addslashes($_SESSION['m_admin']['model']['LABEL'])."', now(),'".addslashes($_SESSION['m_admin']['model']['COMMENT'])."', '".$_SESSION['m_admin']['model']['CONTENT']."', '".$_SESSION['m_admin']['model']['TYPE']."', ".$_SESSION['m_admin']['model']['STYLE'].")");
$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']."' and TYPE = '".$_SESSION['m_admin']['model']['TYPE']."' and STYLE = ".$_SESSION['m_admin']['model']['STYLE']."");
$res = $this->fetch_object();
if ($_SESSION['m_admin']['model']['TYPE'] == 'ODT') {
if (file_exists('include/odtphp/models/model_' . $_SESSION['admin_models']['model_id'] . '.odt')) {
if (!copy('include/odtphp/models/model_' . $_SESSION['admin_models']['model_id'] . '.odt', 'include/odtphp/models/model_' . $res->ID . '.odt')) {
echo "ko";
}
}
}
$_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']);
}
}
for ($i=0;$iquery("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)
{
include('models_fusion.php');
foreach ($resultArray as $key => $value) {
if(preg_match('/DATE/', $key)) {
$content = str_replace("[" . $key . "]", html_entity_decode(utf8_decode($db->inverse_date($value))), $content);
} else {
$content = str_replace("[" . $key . "]", html_entity_decode(utf8_decode(stripslashes($value))), $content);
}
}
$content = str_replace('[NEW_EMETTEUR]', html_entity_decode(utf8_decode($_SESSION['user']['FirstName'])) . ' ' . html_entity_decode(utf8_decode($_SESSION['user']['LastName'])), $content);
$content = str_replace('[PHONE_EMETTEUR]', html_entity_decode(utf8_decode($_SESSION['user']['Phone'])), $content);
$content = str_replace('[DEP_EMETTEUR]', html_entity_decode(utf8_decode($_SESSION['user']['department'])), $content);
$content = str_replace('[MAIL_EMETTEUR]', html_entity_decode(utf8_decode($_SESSION['user']['Mail'])), $content);
$content = str_replace('[DATE_TODAY]', html_entity_decode(utf8_decode(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_once("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;
}
}
}
}