2016-10-06 15:57:01 +00:00
< ? php
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
/**
* Project :
* Contenido Content Management System
*
* Description :
* Define the Template related functions
*
* Requirements :
* @ con_php_req 5.0
*
*
* @ package Contenido Backend includes
* @ version 1.0 . 1
* @ author Olaf Niemann
* @ copyright four for business AG < www . 4 fb . de >
* @ license http :// www . contenido . org / license / LIZENZ . txt
* @ link http :// www . 4 fb . de
* @ link http :// www . contenido . org
* @ since file available since contenido release <= 4.6
*
* { @ internal
* created 2003 - 01 - 21
* modified 2008 - 06 - 26 , Frederic Schneider , add security fix
* modified 2008 - 06 - 30 timo . trautmann added fix module settings were also copied in function tplDuplicateTemplate
* modified 2009 - 01 - 08 , Timo Trautmann fixed bug : Changes in Head Containers in visualedit were not stored
*
2019-07-03 11:58:28 +00:00
* $Id $ :
2016-10-06 15:57:01 +00:00
* }}
*
*/
2019-07-03 19:14:30 +00:00
if ( ! defined ( 'CON_FRAMEWORK' )) {
die ( 'Illegal call' );
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
cInclude ( " includes " , " functions.con.php " );
2016-10-06 15:57:01 +00:00
/**
* Edit or create a new Template
*
* @ author Olaf Niemann < Olaf . Niemann @ 4 fb . de >
* @ author Jan Lengowski < Jan . Lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb . de >
*/
2019-07-03 19:14:30 +00:00
function tplEditTemplate ( $changelayout , $idtpl , $name , $description , $idlay , $c , $default ) {
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
global $db ;
global $sess ;
global $auth ;
global $client ;
global $cfg ;
global $area_tree ;
global $perm ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$db2 = new DB_ConLite ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$date = date ( " YmdHis " );
$author = " " . $auth -> auth [ " uname " ] . " " ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
//******** entry in 'tpl'-table ***************
2021-08-18 12:37:03 +00:00
//set_magic_quotes_gpc($name);
//set_magic_quotes_gpc($description);
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
if ( ! $idtpl ) {
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$idtpl = $db -> nextid ( $cfg [ " tab " ][ " tpl " ]);
$idtplcfg = $db -> nextid ( $cfg [ " tab " ][ " tpl_conf " ]);
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
/* Insert new entry in the
Template Conf table */
$sql = " INSERT INTO " . $cfg [ " tab " ][ " tpl_conf " ] . "
( idtplcfg , idtpl , author ) VALUES
( '" . Contenido_Security::toInteger($idtplcfg) . "' , '" . Contenido_Security::toInteger($idtpl) . "' , '" . Contenido_Security::escapeDB($auth->auth["uname"], $db) . "' ) " ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
/* Insert new entry in the
Template table */
$sql = " INSERT INTO " . $cfg [ " tab " ][ " tpl " ] . "
( idtpl , idtplcfg , name , description , deletable , idlay , idclient , author , created , lastmodified ) VALUES
( '" . Contenido_Security::toInteger($idtpl) . "' , '" . Contenido_Security::toInteger($idtplcfg) . "' , '" . Contenido_Security::escapeDB($name, $db) . "' , '" . Contenido_Security::escapeDB($description, $db) . "' ,
'1' , '" . Contenido_Security::toInteger($idlay) . "' , '" . Contenido_Security::toInteger($client) . "' , '" . Contenido_Security::escapeDB($author, $db) . "' , '" . Contenido_Security::escapeDB($date, $db) . "' ,
'" . Contenido_Security::escapeDB($date, $db) . "' ) " ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
// set correct rights for element
cInclude ( " includes " , " functions.rights.php " );
createRightsForElement ( " tpl " , $idtpl );
} else {
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
/* Update */
$sql = " UPDATE " . $cfg [ " tab " ][ " tpl " ] . " SET name=' " . Contenido_Security :: escapeDB ( $name , $db ) . " ', description=' " . Contenido_Security :: escapeDB ( $description , $db ) . " ', idlay=' " . Contenido_Security :: toInteger ( $idlay ) . " ',
author = '" . Contenido_Security::escapeDB($author, $db) . "' , lastmodified = '" . Contenido_Security::escapeDB($date, $db) . "' WHERE idtpl = '" . Contenido_Security::toInteger($idtpl) . "' " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
if ( is_array ( $c )) {
/* Delete all container assigned to this template */
$sql = " DELETE FROM " . $cfg [ " tab " ][ " container " ] . " WHERE idtpl=' " . Contenido_Security :: toInteger ( $idtpl , $db ) . " ' " ;
$db -> query ( $sql );
foreach ( $c as $idcontainer => $dummyval ) {
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " INSERT INTO " . $cfg [ " tab " ][ " container " ] . " (idcontainer, idtpl, number, idmod) VALUES " ;
$sql .= " ( " ;
$sql .= " ' " . Contenido_Security :: toInteger ( $db -> nextid ( $cfg [ " tab " ][ " container " ])) . " ', " ;
$sql .= " ' " . Contenido_Security :: toInteger ( $idtpl ) . " ', " ;
$sql .= " ' " . Contenido_Security :: toInteger ( $idcontainer ) . " ', " ;
$sql .= " ' " . Contenido_Security :: toInteger ( $c [ $idcontainer ]) . " ' " ;
$sql .= " ) " ;
$db -> query ( $sql );
}
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
/* Generate code */
conGenerateCodeForAllartsUsingTemplate ( $idtpl );
}
if ( $default == 1 ) {
$sql = " UPDATE " . $cfg [ " tab " ][ " tpl " ] . " SET defaulttemplate = '0' WHERE idclient = ' " . Contenido_Security :: toInteger ( $client ) . " ' " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " UPDATE " . $cfg [ " tab " ][ " tpl " ] . " SET defaulttemplate = '1' WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' AND idclient = ' " . Contenido_Security :: toInteger ( $client ) . " ' " ;
$db -> query ( $sql );
} else {
$sql = " UPDATE " . $cfg [ " tab " ][ " tpl " ] . " SET defaulttemplate = '0' WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' AND idclient = ' " . Contenido_Security :: toInteger ( $client ) . " ' " ;
$db -> query ( $sql );
}
//******** if layout is changed stay at 'tpl_edit' otherwise go to 'tpl'
if ( $changelayout != 1 ) {
$url = $sess -> url ( " main.php?area=tpl_edit&idtpl= $idtpl &frame=4 " );
header ( " location: $url " );
}
return $idtpl ;
2016-10-06 15:57:01 +00:00
}
/**
* Delete a template
*
* @ param int $idtpl ID of the template to duplicate
*
* @ return $new_idtpl ID of the duplicated template
* @ author Olaf Niemann < Olaf . Niemann @ 4 fb . de >
* @ author Jan Lengowski < Jan . Lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb .>
*/
function tplDeleteTemplate ( $idtpl ) {
2019-07-03 19:14:30 +00:00
global $db , $client , $lang , $cfg , $area_tree , $perm ;
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " DELETE FROM " . $cfg [ " tab " ][ " tpl " ] . " WHERE idtpl=' " . Contenido_Security :: toInteger ( $idtpl ) . " ' " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
/* JL 160603 : Delete all unnecessary entries */
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " DELETE FROM " . $cfg [ " tab " ][ " container " ] . " WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$idsToDelete = array ();
$sql = " SELECT idtplcfg FROM " . $cfg [ " tab " ][ " tpl_conf " ] . " WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' " ;
$db -> query ( $sql );
while ( $db -> next_record ()) {
$idsToDelete [] = $db -> f ( " idtplcfg " );
}
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
foreach ( $idsToDelete as $id ) {
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " DELETE FROM " . $cfg [ " tab " ][ " tpl_conf " ] . " WHERE idtplcfg = ' " . Contenido_Security :: toInteger ( $id ) . " ' " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " DELETE FROM " . $cfg [ " tab " ][ " container_conf " ] . " WHERE idtplcfg = ' " . Contenido_Security :: toInteger ( $id ) . " ' " ;
$db -> query ( $sql );
}
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
cInclude ( " includes " , " functions.rights.php " );
deleteRightsForElement ( " tpl " , $idtpl );
2016-10-06 15:57:01 +00:00
}
/**
* Browse a specific layout for containers
*
* @ param int $idtpl Layout number to browse
*
* @ return string &- seperated String of all containers
*
* @ author Jan Lengowski < Jan . Lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb .>
*/
function tplBrowseLayoutForContainers ( $idlay , $raw_code = NULL ) {
2019-07-03 19:14:30 +00:00
global $db ;
global $cfg ;
global $containerinf ;
if ( is_null ( $raw_code ) || empty ( $raw_code )) {
$sql = " SELECT code FROM " . $cfg [ " tab " ][ " lay " ] . " WHERE idlay=' " . Contenido_Security :: toInteger ( $idlay ) . " ' " ;
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
$db -> next_record ();
$code = $db -> f ( " code " );
} else {
$code = $raw_code ;
}
2019-07-03 19:14:30 +00:00
preg_match_all ( " /CMS_CONTAINER \ [([0-9]*) \ ]/ " , $code , $a_container );
$iPosBody = stripos ( $code , '<body>' );
$sCodeBeforeHeader = substr ( $code , 0 , $iPosBody );
foreach ( $a_container [ 1 ] as $value ) {
if ( preg_match ( " /CMS_CONTAINER \ [ $value\ ]/ " , $sCodeBeforeHeader )) {
$containerinf [ $idlay ][ $value ][ " is_body " ] = false ;
} else {
$containerinf [ $idlay ][ $value ][ " is_body " ] = true ;
}
}
2016-10-06 15:57:01 +00:00
if ( is_array ( $containerinf [ $idlay ])) {
foreach ( $containerinf [ $idlay ] as $key => $value ) {
2019-07-03 19:14:30 +00:00
$a_container [ 1 ][] = $key ;
}
}
$container = Array ();
2016-10-06 15:57:01 +00:00
foreach ( $a_container [ 1 ] as $value ) {
if ( ! in_array ( $value , $container )) {
2019-07-03 19:14:30 +00:00
$container [] = $value ;
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
}
asort ( $container );
if ( is_array ( $container )) {
$tmp_returnstring = implode ( " & " , $container );
}
return $tmp_returnstring ;
2016-10-06 15:57:01 +00:00
}
/**
* Retrieve the container name
*
* @ param int $idtpl Layout number to browse
* @ param int $container Container number
*
* @ return string Container name
*/
2019-07-03 19:14:30 +00:00
function tplGetContainerName ( $idlay , $container ) {
global $db ;
global $cfg ;
global $containerinf ;
if ( is_array ( $containerinf [ $idlay ])) {
if ( array_key_exists ( $container , $containerinf [ $idlay ])) {
return $containerinf [ $idlay ][ $container ][ " name " ];
}
}
2016-10-06 15:57:01 +00:00
}
/**
* Retrieve the container mode
*
* @ param int $idtpl Layout number to browse
* @ param int $container Container number
*
* @ return string Container name
*/
2019-07-03 19:14:30 +00:00
function tplGetContainerMode ( $idlay , $container ) {
global $db ;
global $cfg ;
global $containerinf ;
if ( is_array ( $containerinf [ $idlay ])) {
if ( array_key_exists ( $container , $containerinf [ $idlay ])) {
return $containerinf [ $idlay ][ $container ][ " mode " ];
}
}
2016-10-06 15:57:01 +00:00
}
/**
* Retrieve the allowed container types
*
* @ param int $idtpl Layout number to browse
* @ param int $container Container number
*
* @ return array Allowed container types
*/
2019-07-03 19:14:30 +00:00
function tplGetContainerTypes ( $idlay , $container ) {
global $db ;
global $cfg ;
global $containerinf ;
2019-07-07 18:14:22 +00:00
$list = array ();
2019-07-03 19:14:30 +00:00
if ( is_array ( $containerinf [ $idlay ])) {
if ( array_key_exists ( $container , $containerinf [ $idlay ])) {
if ( $containerinf [ $idlay ][ $container ][ " types " ] != " " ) {
$list = explode ( " , " , $containerinf [ $idlay ][ $container ][ " types " ]);
foreach ( $list as $key => $value ) {
$list [ $key ] = trim ( $value );
}
}
}
}
2019-07-07 18:14:22 +00:00
return $list ;
2016-10-06 15:57:01 +00:00
}
/**
* Retrieve the default module
*
* @ param int $idtpl Layout number to browse
* @ param int $container Container number
*
* @ return array Allowed container types
*/
2019-07-03 19:14:30 +00:00
function tplGetContainerDefault ( $idlay , $container ) {
global $db ;
global $cfg ;
global $containerinf ;
if ( is_array ( $containerinf [ $idlay ])) {
if ( array_key_exists ( $container , $containerinf [ $idlay ])) {
return $containerinf [ $idlay ][ $container ][ " default " ];
}
}
2016-10-06 15:57:01 +00:00
}
/**
* Preparse the layout for caching purposes
*
* @ param int $idtpl Layout number to browse
*
* @ return none
*/
2019-07-03 19:14:30 +00:00
function tplPreparseLayout ( $idlay , $raw_code = NULL ) {
2016-10-06 15:57:01 +00:00
global $containerinf ;
global $db ;
global $cfg ;
2019-07-03 19:14:30 +00:00
if ( is_null ( $raw_code ) || empty ( $raw_code )) {
$sql = " SELECT code FROM " . $cfg [ " tab " ][ " lay " ] . " WHERE idlay=' " . Contenido_Security :: toInteger ( $idlay ) . " ' " ;
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
$db -> next_record ();
$code = $db -> f ( " code " );
} else {
$code = $raw_code ;
}
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
$parser = new HtmlParser ( $code );
$bIsBody = false ;
2019-07-03 19:14:30 +00:00
while ( $parser -> parse ()) {
if ( strtolower ( $parser -> iNodeName ) == 'body' ) {
$bIsBody = true ;
}
if ( $parser -> iNodeName == " container " && $parser -> iNodeType == NODE_TYPE_ELEMENT ) {
$idcontainer = $parser -> iNodeAttributes [ " id " ];
$mode = $parser -> iNodeAttributes [ " mode " ];
if ( $mode == " " ) {
$mode = " optional " ;
}
$containerinf [ $idlay ][ $idcontainer ][ " name " ] = $parser -> iNodeAttributes [ " name " ];
$containerinf [ $idlay ][ $idcontainer ][ " mode " ] = $mode ;
$containerinf [ $idlay ][ $idcontainer ][ " default " ] = $parser -> iNodeAttributes [ " default " ];
$containerinf [ $idlay ][ $idcontainer ][ " types " ] = $parser -> iNodeAttributes [ " types " ];
$containerinf [ $idlay ][ $idcontainer ][ " is_body " ] = $bIsBody ;
}
}
2016-10-06 15:57:01 +00:00
}
/**
* Duplicate a template
*
* @ param int $idtpl ID of the template to duplicate
*
* @ return $new_idtpl ID of the duplicated template
*
* @ author Jan Lengowski < Jan . Lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb .>
*/
function tplDuplicateTemplate ( $idtpl ) {
global $db , $client , $lang , $cfg , $sess , $auth ;
$db2 = new DB_ConLite ;
$sql = " SELECT
*
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " tpl " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
idtpl = '" . Contenido_Security::toInteger($idtpl) . "' " ;
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
$db -> next_record ();
2019-07-03 19:14:30 +00:00
$idclient = $db -> f ( " idclient " );
$idlay = $db -> f ( " idlay " );
$new_idtpl = $db -> nextid ( $cfg [ " tab " ][ " tpl " ]);
//modified (added) 2008-06-30 timo.trautmann added fix module settings were also copied
$idtpl_conf = $db -> f ( " idtplcfg " );
if ( $idtpl_conf ) {
$new_idtpl_conf = $db -> nextid ( $cfg [ " tab " ][ " tpl_conf " ]);
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
//modified (added) 2008-06-30 end
$name = sprintf ( i18n ( " %s (Copy) " ), $db -> f ( " name " ));
$descr = $db -> f ( " description " );
$author = $auth -> auth [ " uname " ];
$created = time ();
$lastmod = time ();
//modified (added) 2008-06-30 : idtplcfg -> $new_idtpl
2016-10-06 15:57:01 +00:00
$sql = " INSERT INTO
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " tpl " ] . "
( idclient , idlay , idtpl , " . ( $idtpl_conf ? 'idtplcfg,' : '') . " name , description , deletable , author , created , lastmodified )
2016-10-06 15:57:01 +00:00
VALUES
2019-07-03 19:14:30 +00:00
( '" . Contenido_Security::toInteger($idclient) . "' , '" . Contenido_Security::toInteger($idlay) . "' , '" . Contenido_Security::toInteger($new_idtpl) . "' , " . ( $idtpl_conf ? " '" . Contenido_Security::toInteger($new_idtpl_conf) . "' , " : '') . " '" . Contenido_Security::escapeDB($name, $db) . "' ,
'" . Contenido_Security::escapeDB($descr, $db) . "' , '1' , '" . Contenido_Security::escapeDB($author, $db) . "' , '" . Contenido_Security::escapeDB($created, $db) . "' , '" . Contenido_Security::escapeDB($lastmod, $db) . "' ) " ;
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
$a_containers = array ();
$sql = " SELECT
*
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " container " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
idtpl = '" . Contenido_Security::toInteger($idtpl) . "'
2016-10-06 15:57:01 +00:00
ORDER BY
number " ;
$db -> query ( $sql );
while ( $db -> next_record ()) {
$a_containers [ $db -> f ( " number " )] = $db -> f ( " idmod " );
}
foreach ( $a_containers as $key => $value ) {
$nextid = $db -> nextid ( $cfg [ " tab " ][ " container " ]);
2019-07-03 19:14:30 +00:00
$sql = " INSERT INTO " . $cfg [ " tab " ][ " container " ] . "
( idcontainer , idtpl , number , idmod ) VALUES ( '" . Contenido_Security::toInteger($nextid) . "' , '" . Contenido_Security::toInteger($new_idtpl) . "' , '" . Contenido_Security::toInteger($key) . "' , '" . Contenido_Security::toInteger($value) . "' ) " ;
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
}
2019-07-03 19:14:30 +00:00
//modified (added) 2008-06-30 timo.trautmann added fix module settings were also copied
if ( $idtpl_conf ) {
2016-10-06 15:57:01 +00:00
$a_container_cfg = array ();
$sql = " SELECT
*
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " container_conf " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
idtplcfg = '" . Contenido_Security::toInteger($idtpl_conf) . "'
2016-10-06 15:57:01 +00:00
ORDER BY
number " ;
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
$db -> query ( $sql );
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
while ( $db -> next_record ()) {
2019-07-03 19:14:30 +00:00
$a_container_cfg [ $db -> f ( " number " )] = $db -> f ( " container " );
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
foreach ( $a_container_cfg as $key => $value ) {
2019-07-03 19:14:30 +00:00
$nextid = $db -> nextid ( $cfg [ " tab " ][ " container_conf " ]);
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$sql = " INSERT INTO " . $cfg [ " tab " ][ " container_conf " ] . "
( idcontainerc , idtplcfg , number , container ) VALUES ( '" . Contenido_Security::toInteger($nextid) . "' , '" . Contenido_Security::toInteger($new_idtpl_conf) . "' , '" . Contenido_Security::escapeDB($key, $db) . "' , '" . Contenido_Security::escapeDB($value, $db) . "' ) " ;
$db -> query ( $sql );
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
}
//modified (added) 2008-06-30 end
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
cInclude ( " includes " , " functions.rights.php " );
2016-10-06 15:57:01 +00:00
copyRightsForElement ( " tpl " , $idtpl , $new_idtpl );
2019-07-03 19:14:30 +00:00
return $new_idtpl ;
2016-10-06 15:57:01 +00:00
}
/**
* Checks if a template is in use
*
* @ param int $idtpl Template ID
*
* @ return bool is template in use
*
* @ author Jan Lengowski < Jan . Lengowski @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb . de >
*
* modified Munkh - Ulzii Balidar , improved the sql query without while loop
*/
function tplIsTemplateInUse ( $idtpl ) {
global $cfg , $client , $lang ;
$db = new DB_ConLite ;
// Check categorys
$sql = " SELECT
b . idcatlang , b . name , b . idlang , b . idcat
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " cat " ] . " AS a ,
" . $cfg["tab"] [ " cat_lang " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
a . idclient = '" . Contenido_Security::toInteger($client) . "' AND
2016-10-06 15:57:01 +00:00
a . idcat = b . idcat AND
2019-07-03 19:14:30 +00:00
b . idtplcfg IN ( SELECT idtplcfg FROM " . $cfg["tab"] [ " tpl_conf " ] . " WHERE idtpl = '" . $idtpl . "' )
2016-10-06 15:57:01 +00:00
ORDER BY b . idlang ASC , b . name ASC " ;
$db -> query ( $sql );
if ( $db -> Errno == '' && $db -> num_rows () > 0 ) {
2019-07-03 19:14:30 +00:00
return true ;
2016-10-06 15:57:01 +00:00
}
// Check articles
$sql = " SELECT
b . idartlang , b . title , b . idlang , b . idart
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " art " ] . " AS a ,
" . $cfg["tab"] [ " art_lang " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
a . idclient = '" . Contenido_Security::toInteger($client) . "' AND
2016-10-06 15:57:01 +00:00
a . idart = b . idart AND
2019-07-03 19:14:30 +00:00
b . idtplcfg IN ( SELECT idtplcfg FROM " . $cfg["tab"] [ " tpl_conf " ] . " WHERE idtpl = '" . $idtpl . "' )
2016-10-06 15:57:01 +00:00
ORDER BY b . idlang ASC , b . title ASC " ;
$db -> query ( $sql );
if ( $db -> Errno == '' && $db -> num_rows () > 0 ) {
2019-07-03 19:14:30 +00:00
return true ;
2016-10-06 15:57:01 +00:00
}
2019-07-03 19:14:30 +00:00
return false ;
2016-10-06 15:57:01 +00:00
}
/**
* Get used datas if a template is in use
*
* @ param int $idtpl Template ID
*
* @ return array - category name , article name
*
* @ author Munkh - Ulzii Balidar < munkh - ulzii . balidar @ 4 fb . de >
* @ copyright four for business AG < www . 4 fb . de >
*/
function tplGetInUsedData ( $idtpl ) {
global $cfg , $client , $lang ;
$db = new DB_ConLite ;
2019-07-03 19:14:30 +00:00
2016-10-06 15:57:01 +00:00
$aUsedData = array ();
// Check categorys
$sql = " SELECT
b . idcatlang , b . name , b . idlang , b . idcat
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " cat " ] . " AS a ,
" . $cfg["tab"] [ " cat_lang " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
a . idclient = '" . Contenido_Security::toInteger($client) . "' AND
2016-10-06 15:57:01 +00:00
a . idcat = b . idcat AND
2019-07-03 19:14:30 +00:00
b . idtplcfg IN ( SELECT idtplcfg FROM " . $cfg["tab"] [ " tpl_conf " ] . " WHERE idtpl = '" . $idtpl . "' )
2016-10-06 15:57:01 +00:00
ORDER BY b . idlang ASC , b . name ASC " ;
$db -> query ( $sql );
if ( $db -> Errno == 0 && $db -> num_rows () > 0 ) {
2019-07-03 19:14:30 +00:00
while ( $db -> next_record ()) {
$aUsedData [ 'cat' ][] = array (
'name' => $db -> f ( 'name' ),
'lang' => $db -> f ( 'idlang' ),
'idcat' => $db -> f ( 'idcat' ),
);
}
2016-10-06 15:57:01 +00:00
}
// Check articles
$sql = " SELECT
b . idartlang , b . title , b . idlang , b . idart
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " art " ] . " AS a ,
" . $cfg["tab"] [ " art_lang " ] . " AS b
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
a . idclient = '" . Contenido_Security::toInteger($client) . "' AND
2016-10-06 15:57:01 +00:00
a . idart = b . idart AND
2019-07-03 19:14:30 +00:00
b . idtplcfg IN ( SELECT idtplcfg FROM " . $cfg["tab"] [ " tpl_conf " ] . " WHERE idtpl = '" . $idtpl . "' )
2016-10-06 15:57:01 +00:00
ORDER BY b . idlang ASC , b . title ASC " ;
$db -> query ( $sql );
if ( $db -> Errno == '' && $db -> num_rows () > 0 ) {
2019-07-03 19:14:30 +00:00
while ( $db -> next_record ()) {
$aUsedData [ 'art' ][] = array (
'title' => $db -> f ( 'title' ),
'lang' => $db -> f ( 'idlang' ),
'idart' => $db -> f ( 'idart' ),
);
}
2016-10-06 15:57:01 +00:00
}
return $aUsedData ;
}
/**
* Copies a complete template configuration
*
* @ param int $idtplcfg Template Configuration ID
*
* @ return int new template configuration ID
*
*/
2019-07-03 19:14:30 +00:00
function tplcfgDuplicate ( $idtplcfg ) {
global $cfg ;
$db = new DB_ConLite ;
$db2 = new DB_ConLite ;
$sql = " SELECT
2016-10-06 15:57:01 +00:00
idtpl , status , author , created , lastmodified
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " tpl_conf " ] . "
2016-10-06 15:57:01 +00:00
WHERE
2019-07-03 19:14:30 +00:00
idtplcfg = '" . Contenido_Security::toInteger($idtplcfg) . "' " ;
$db -> query ( $sql );
if ( $db -> next_record ()) {
$newidtplcfg = $db2 -> nextid ( $cfg [ " tab " ][ " tpl_conf " ]);
$idtpl = $db -> f ( " idtpl " );
$status = $db -> f ( " status " );
$author = $db -> f ( " author " );
$created = $db -> f ( " created " );
$lastmodified = $db -> f ( " lastmodified " );
$sql = " INSERT INTO
" . $cfg["tab"] [ " tpl_conf " ] . "
2016-10-06 15:57:01 +00:00
( idtplcfg , idtpl , status , author , created , lastmodified )
VALUES
2019-07-03 19:14:30 +00:00
( '" . Contenido_Security::toInteger($newidtplcfg) . "' , '" . Contenido_Security::toInteger($idtpl) . "' , '" . Contenido_Security::toInteger($status) . "' , '" . Contenido_Security::escapeDB($author, $db2) . "' ,
'" . Contenido_Security::escapeDB($created, $db2) . "' , '" . Contenido_Security::escapeDB($lastmodified, $db2) . "' ) " ;
$db2 -> query ( $sql );
/* Copy container configuration */
$sql = " SELECT
2016-10-06 15:57:01 +00:00
number , container
FROM
2019-07-03 19:14:30 +00:00
" . $cfg["tab"] [ " container_conf " ] . "
WHERE idtplcfg = '" . Contenido_Security::toInteger($idtplcfg) . "' " ;
$db -> query ( $sql );
while ( $db -> next_record ()) {
$newidcontainerc = $db2 -> nextid ( $cfg [ " tab " ][ " container_conf " ]);
$number = $db -> f ( " number " );
$container = $db -> f ( " container " );
$sql = " INSERT INTO
" . $cfg["tab"] [ " container_conf " ] . "
2016-10-06 15:57:01 +00:00
( idcontainerc , idtplcfg , number , container )
VALUES
2019-07-03 19:14:30 +00:00
( '" . Contenido_Security::toInteger($newidcontainerc) . "' , '" . Contenido_Security::toInteger($newidtplcfg) . "' , '" . Contenido_Security::toInteger($number) . "' , '" . Contenido_Security::escapeDB($container, $db2) . "' ) " ;
$db2 -> query ( $sql );
}
}
return ( $newidtplcfg );
2016-10-06 15:57:01 +00:00
}
/*
* tplAutoFillModules
*
* This function fills in modules automatically using this logic :
*
* - If the container mode is fixed , insert the named module ( if exists )
* - If the container mode is mandatory , insert the " default " module ( if exists )
*
* TODO : The default module is only inserted in mandatory mode if the container
* is empty . We need a better logic for handling " changes " .
*/
2019-07-03 19:14:30 +00:00
function tplAutoFillModules ( $idtpl ) {
global $cfg ;
global $db_autofill ;
global $containerinf ;
global $_autoFillcontainerCache ;
if ( ! is_object ( $db_autofill )) {
$db_autofill = new DB_ConLite ;
}
$sql = " SELECT idlay FROM " . $cfg [ " tab " ][ " tpl " ] . " WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' " ;
$db_autofill -> query ( $sql );
if ( ! $db_autofill -> next_record ()) {
return false ;
}
2016-10-06 15:57:01 +00:00
2019-07-03 19:14:30 +00:00
$idlay = $db_autofill -> f ( " idlay " );
if ( ! ( is_array ( $containerinf ) && array_key_exists ( $idlay , $containerinf ) && array_key_exists ( $idlay , $_autoFillcontainerCache ))) {
tplPreparseLayout ( $idlay );
$_autoFillcontainerCache [ $idlay ] = tplBrowseLayoutForContainers ( $idlay );
}
$a_container = explode ( " & " , $_autoFillcontainerCache [ $idlay ]);
foreach ( $a_container as $container ) {
switch ( $containerinf [ $idlay ][ $container ][ " mode " ]) {
/* Fixed mode */
case " fixed " :
if ( $containerinf [ $idlay ][ $container ][ " default " ] != " " ) {
$sql = " SELECT idmod FROM " . $cfg [ " tab " ][ " mod " ]
. " WHERE name = ' " .
Contenido_Security :: escapeDB ( $containerinf [ $idlay ][ $container ][ " default " ], $db_autofill ) . " ' " ;
$db_autofill -> query ( $sql );
if ( $db_autofill -> next_record ()) {
$idmod = $db_autofill -> f ( " idmod " );
$sql = " SELECT idcontainer FROM " . $cfg [ " tab " ][ " container " ] . " WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' AND number = ' " . Contenido_Security :: toInteger ( $container ) . " ' " ;
$db_autofill -> query ( $sql );
if ( $db_autofill -> next_record ()) {
$sql = " UPDATE " . $cfg [ " tab " ][ " container " ] .
" SET idmod = ' " . Contenido_Security :: toInteger ( $idmod ) . " ' WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' " .
" AND number = ' " . Contenido_Security :: toInteger ( $container ) . " ' AND " .
" idcontainer = ' " . Contenido_Security :: toInteger ( $db_autofill -> f ( " idcontainer " )) . " ' " ;
$db_autofill -> query ( $sql );
} else {
$sql = " INSERT INTO " . $cfg [ " tab " ][ " container " ] .
" (idcontainer, idtpl, number, idmod) " .
" VALUES (' " . $db_autofill -> nextid ( $cfg [ " tab " ][ " container " ]) . " ', " .
" ' $idtpl ', ' $container ', ' $idmod ') " ;
$db_autofill -> query ( $sql );
}
}
}
case " mandatory " :
if ( $containerinf [ $idlay ][ $container ][ " default " ] != " " ) {
$sql = " SELECT idmod FROM " . $cfg [ " tab " ][ " mod " ]
. " WHERE name = ' " .
Contenido_Security :: escapeDB ( $containerinf [ $idlay ][ $container ][ " default " ], $db ) . " ' " ;
$db_autofill -> query ( $sql );
if ( $db_autofill -> next_record ()) {
$idmod = $db_autofill -> f ( " idmod " );
$sql = " SELECT idcontainer, idmod FROM " . $cfg [ " tab " ][ " container " ]
. " WHERE idtpl = ' " . Contenido_Security :: toInteger ( $idtpl ) . " ' AND number = ' " . Contenido_Security :: toInteger ( $container ) . " ' " ;
$db_autofill -> query ( $sql );
if ( $db_autofill -> next_record ()) {
} else {
$sql = " INSERT INTO " . $cfg [ " tab " ][ " container " ] .
" (idcontainer, idtpl, number, idmod) " .
" VALUES (' " . Contenido_Security :: toInteger ( $db_autofill -> nextid ( $cfg [ " tab " ][ " container " ])) . " ', " .
" ' " . Contenido_Security :: toInteger ( $idtpl ) . " ', ' " . Contenido_Security :: toInteger ( $container ) . " ', ' " . Contenido_Security :: toInteger ( $idmod ) . " ') " ;
$db_autofill -> query ( $sql );
}
}
}
}
}
2016-10-06 15:57:01 +00:00
}
?>