Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateInfoButton
  • generateJs
  • getAktuellType
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • xmlFileToArray
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the CONTENIDO template functions.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       Backend
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Olaf Niemann, Jan Lengowski, Munkh-Ulzii Balidar
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: cInclude("includes", "functions.con.php");
 19: 
 20: /**
 21:  * Edit or create a new Template
 22:  */
 23: function tplEditTemplate($changelayout, $idtpl, $name, $description, $idlay, $c, $default)
 24: {
 25:         global $db;
 26:         global $sess;
 27:         global $auth;
 28:         global $client;
 29:         global $cfg;
 30:         global $area_tree;
 31:         global $perm;
 32: 
 33:         $db2= cRegistry::getDb();
 34:         $date = date('Y-m-d H:i:s');
 35:         $author = "".$auth->auth["uname"]."";
 36: 
 37:         //******** entry in 'tpl'-table ***************
 38:         set_magic_quotes_gpc($name);
 39:         set_magic_quotes_gpc($description);
 40: 
 41:         $template = new cApiTemplate();
 42:         $template->loadBy("name", $name);
 43:         if ($template->isLoaded() && $template->get('idtpl') != $idtpl) {
 44:             cRegistry::addErrorMessage(i18n("Template name already exists"));
 45:             return -1;
 46:         }
 47: 
 48:         if (!$idtpl) {
 49:             /* Insert new entry in the
 50:                Template table  */
 51:             $sql = "INSERT INTO ".$cfg["tab"]["tpl"]."
 52:                     (idtplcfg, name, description, deletable, idlay, idclient, author, created, lastmodified) VALUES
 53:                     ('".cSecurity::toInteger(0)."', '".cSecurity::escapeDB($name, $db)."', '".cSecurity::escapeDB($description, $db)."',
 54:                     '1', '".cSecurity::toInteger($idlay)."', '".cSecurity::toInteger($client)."', '".cSecurity::escapeDB($author, $db)."', '".cSecurity::escapeDB($date, $db)."',
 55:                     '".cSecurity::escapeDB($date, $db)."')";
 56: 
 57:             $db->query($sql);
 58:             $idtpl = $db->getLastInsertedId($cfg["tab"]["tpl"]);
 59: 
 60:             /* Insert new entry in the
 61:                Template Conf table  */
 62:             $sql = "INSERT INTO ".$cfg["tab"]["tpl_conf"]."
 63:                     (idtpl, author) VALUES
 64:                    ('".cSecurity::toInteger($idtpl)."', '".cSecurity::escapeDB($auth->auth["uname"], $db)."')";
 65: 
 66:             $db->query($sql);
 67:             $idtplcfg = $db->getLastInsertedId($cfg["tab"]["tpl_conf"]);
 68: 
 69:             /* Update new idtplconf*/
 70:             $sql = "UPDATE ".$cfg["tab"]["tpl"]." SET idtplcfg='".cSecurity::toInteger($idtplcfg)."'
 71:             WHERE idtpl='".cSecurity::toInteger($idtpl)."'";
 72:             $db->query($sql);
 73: 
 74:             // set correct rights for element
 75:             cInclude("includes", "functions.rights.php");
 76:             createRightsForElement("tpl", $idtpl);
 77: 
 78: 
 79:         } else {
 80: 
 81:             /* Update */
 82:             $sql = "UPDATE ".$cfg["tab"]["tpl"]." SET name='".cSecurity::escapeDB($name, $db)."', description='".cSecurity::escapeDB($description, $db)."', idlay='".cSecurity::toInteger($idlay)."',
 83:                     author='".cSecurity::escapeDB($author, $db)."', lastmodified='".cSecurity::escapeDB($date, $db)."' WHERE idtpl='".cSecurity::toInteger($idtpl)."'";
 84:             $db->query($sql);
 85: 
 86:             if (is_array($c)) {
 87: 
 88:                 /* Delete all container assigned to this template */
 89:                   $sql = "DELETE FROM ".$cfg["tab"]["container"]." WHERE idtpl='".cSecurity::toInteger($idtpl, $db)."'";
 90:                   $db->query($sql);
 91: 
 92:                foreach ($c as $idcontainer => $dummyval) {
 93: 
 94:                   $sql = "INSERT INTO ".$cfg["tab"]["container"]." (idtpl, number, idmod) VALUES ";
 95:                   $sql .= "(";
 96:                   $sql .= "'".cSecurity::toInteger($idtpl)."', ";
 97:                   $sql .= "'".cSecurity::toInteger($idcontainer)."', ";
 98:                   $sql .= "'".cSecurity::toInteger($c[$idcontainer])."'";
 99:                   $sql .= ") ";
100:                   $db->query($sql);
101: 
102:                }
103:             }
104: 
105:             /* Generate code */
106:             conGenerateCodeForAllartsUsingTemplate($idtpl);
107: 
108:         }
109: 
110:         if ($default == 1)
111:         {
112:             $sql = "UPDATE ".$cfg["tab"]["tpl"]." SET defaulttemplate = '0' WHERE idclient = '".cSecurity::toInteger($client)."'";
113:             $db->query($sql);
114: 
115:             $sql = "UPDATE ".$cfg["tab"]["tpl"]." SET defaulttemplate = '1' WHERE idtpl = '".cSecurity::toInteger($idtpl)."' AND idclient = '".cSecurity::toInteger($client)."'";
116:             $db->query($sql);
117:         } else {
118:             $sql = "UPDATE ".$cfg["tab"]["tpl"]." SET defaulttemplate = '0' WHERE idtpl = '".cSecurity::toInteger($idtpl)."' AND idclient = '".cSecurity::toInteger($client)."'";
119:             $db->query($sql);
120:         }
121: 
122: 
123:         //******** if layout is changed stay at 'tpl_edit' otherwise go to 'tpl'
124:         //if ($changelayout != 1) {
125:          //   $url = $sess->url("main.php?area=tpl_edit&idtpl=$idtpl&frame=4&blubi=blubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
126:           //  header("location: $url");
127:         //}
128: 
129:         return $idtpl;
130: 
131: }
132: 
133: /**
134:  * Delete a template
135:  *
136:  * @param int $idtpl ID of the template to duplicate
137:  *
138:  * @return $new_idtpl ID of the duplicated template
139:  */
140: function tplDeleteTemplate($idtpl) {
141: 
142:         global $db, $client, $lang, $cfg, $area_tree, $perm;
143: 
144:         $sql = "DELETE FROM ".$cfg["tab"]["tpl"]." WHERE idtpl='".cSecurity::toInteger($idtpl)."'";
145:         $db->query($sql);
146: 
147:         /* JL 160603 : Delete all unnecessary entries */
148: 
149:         $sql = "DELETE FROM ".$cfg["tab"]["container"]." WHERE idtpl = '".cSecurity::toInteger($idtpl)."'";
150:         $db->query($sql);
151: 
152:         $idsToDelete = array();
153:         $sql = "SELECT idtplcfg FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtpl = '".cSecurity::toInteger($idtpl)."'";
154:         $db->query($sql);
155:         while ($db->nextRecord()) {
156:             $idsToDelete[] = $db->f("idtplcfg");
157:         }
158: 
159:         foreach ($idsToDelete as $id) {
160: 
161:             $sql = "DELETE FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtplcfg = '".cSecurity::toInteger($id)."'";
162:             $db->query($sql);
163: 
164:             $sql = "DELETE FROM ".$cfg["tab"]["container_conf"]." WHERE idtplcfg = '".cSecurity::toInteger($id)."'";
165:             $db->query($sql);
166: 
167:         }
168: 
169:         cInclude("includes", "functions.rights.php");
170:         deleteRightsForElement("tpl", $idtpl);
171: 
172: }
173: 
174: 
175: /**
176:  * Browse a specific layout for containers
177:  *
178:  * @param int $idtpl Layout number to browse
179:  *
180:  * @return string &-seperated String of all containers
181:  */
182: function tplBrowseLayoutForContainers($idlay) {
183:         global $db;
184:         global $cfg;
185:         global $containerinf;
186:         global $lang;
187: 
188:         $layoutInFile = new cLayoutHandler($idlay, "", $cfg, $lang);
189:         $code = $layoutInFile->getLayoutCode();
190: 
191: 
192:         preg_match_all ("/CMS_CONTAINER\[([0-9]*)\]/", $code, $a_container);
193:         $iPosBody = stripos($code, '<body>');
194:         $sCodeBeforeHeader = substr($code, 0, $iPosBody);
195: 
196:         foreach ($a_container[1] as $value) {
197:             if (preg_match("/CMS_CONTAINER\[$value\]/", $sCodeBeforeHeader)) {
198:                 $containerinf[$idlay][$value]["is_body"] = false;
199:             } else {
200:                 $containerinf[$idlay][$value]["is_body"] = true;
201:             }
202:         }
203: 
204:         if (is_array($containerinf[$idlay]))
205:         {
206:             foreach ($containerinf[$idlay] as $key => $value)
207:             {
208:                 $a_container[1][] = $key;
209:             }
210:         }
211: 
212:         $container = Array();
213: 
214:         foreach ($a_container[1] as $value)
215:         {
216:             if (!in_array($value, $container))
217:             {
218:                 $container[] = $value;
219:             }
220:         }
221: 
222:         asort($container);
223: 
224:         if (is_array($container)) {
225:             $tmp_returnstring = implode("&",$container);
226:         }
227:         return $tmp_returnstring;
228: }
229: 
230: /**
231:  * Retrieve the container name
232:  *
233:  * @param int $idtpl Layout number to browse
234:  * @param int $container Container number
235:  *
236:  * @return string Container name
237:  */
238: function tplGetContainerName($idlay, $container)
239: {
240:         global $db;
241:         global $cfg;
242:         global $containerinf;
243: 
244:         if (is_array($containerinf[$idlay]))
245:         {
246:             if (array_key_exists($container, $containerinf[$idlay]))
247:             {
248:                 return $containerinf[$idlay][$container]["name"];
249:             }
250:         }
251: }
252: 
253: /**
254:  * Retrieve the container mode
255:  *
256:  * @param int $idtpl Layout number to browse
257:  * @param int $container Container number
258:  *
259:  * @return string Container name
260:  */
261: function tplGetContainerMode($idlay, $container)
262: {
263:         global $db;
264:         global $cfg;
265:         global $containerinf;
266: 
267:         if (is_array($containerinf[$idlay]))
268:         {
269:             if (array_key_exists($container, $containerinf[$idlay]))
270:             {
271:                 return $containerinf[$idlay][$container]["mode"];
272:             }
273:         }
274: }
275: 
276: /**
277:  * Retrieve the allowed container types
278:  *
279:  * @param int $idtpl Layout number to browse
280:  * @param int $container Container number
281:  *
282:  * @return array Allowed container types
283:  */
284: function tplGetContainerTypes($idlay, $container)
285: {
286:         global $db;
287:         global $cfg;
288:         global $containerinf;
289: 
290:         if (is_array($containerinf[$idlay]))
291:         {
292:             if (array_key_exists($container, $containerinf[$idlay]))
293:             {
294:                 if ($containerinf[$idlay][$container]["types"] != "")
295:                 {
296:                     $list = explode(",",$containerinf[$idlay][$container]["types"]);
297: 
298:                     foreach ($list as $key => $value)
299:                     {
300:                         $list[$key] = trim($value);
301:                     }
302:                     return $list;
303:                 }
304:             }
305:         }
306: }
307: 
308: /**
309:  * Retrieve the default module
310:  *
311:  * @param int $idtpl Layout number to browse
312:  * @param int $container Container number
313:  *
314:  * @return array Allowed container types
315:  */
316: function tplGetContainerDefault($idlay, $container)
317: {
318:         global $db;
319:         global $cfg;
320:         global $containerinf;
321: 
322:         if (is_array($containerinf[$idlay]))
323:         {
324:             if (array_key_exists($container, $containerinf[$idlay]))
325:             {
326:                 return $containerinf[$idlay][$container]["default"];
327:             }
328:         }
329: }
330: 
331: /**
332:  * Preparse the layout for caching purposes
333:  *
334:  * @param int $idtpl Layout number to browse
335:  */
336: function tplPreparseLayout ($idlay)
337: {
338:     global $containerinf;
339:     global $db;
340:     global $cfg;
341:     global $lang;
342: 
343:     $layoutInFile = new cLayoutHandler($idlay, "", $cfg, $lang);
344:     $code = $layoutInFile->getLayoutCode();
345: 
346:     $parser = new HtmlParser($code);
347:     $bIsBody = false;
348:     while ($parser->parse())
349:     {
350:         if (strtolower($parser->iNodeName) == 'body') {
351:             $bIsBody = true;
352:         }
353: 
354:         if ($parser->iNodeName == "container" && $parser->iNodeType == HtmlParser::NODE_TYPE_ELEMENT)
355:         {
356:             $idcontainer = $parser->iNodeAttributes["id"];
357: 
358:             $mode = $parser->iNodeAttributes["mode"];
359: 
360:             if ($mode == "")
361:             {
362:                 $mode = "optional";
363:             }
364: 
365:             $containerinf[$idlay][$idcontainer]["name"] = $parser->iNodeAttributes["name"];
366:             $containerinf[$idlay][$idcontainer]["mode"] = $mode;
367:             $containerinf[$idlay][$idcontainer]["default"] = $parser->iNodeAttributes["default"];
368:             $containerinf[$idlay][$idcontainer]["types"] = $parser->iNodeAttributes["types"];
369:             $containerinf[$idlay][$idcontainer]["is_body"] = $bIsBody;
370:         }
371:     }
372: }
373: 
374: /**
375:  * Duplicate a template
376:  *
377:  * @param int $idtpl ID of the template to duplicate
378:  *
379:  * @return $new_idtpl ID of the duplicated template
380:  */
381: function tplDuplicateTemplate($idtpl) {
382: 
383:     global $db, $client, $lang, $cfg, $sess, $auth;
384: 
385:     $db2 = cRegistry::getDb();
386: 
387:     $sql = "SELECT
388:                 *
389:             FROM
390:                 ".$cfg["tab"]["tpl"]."
391:             WHERE
392:                 idtpl = '".cSecurity::toInteger($idtpl)."'";
393: 
394:     $db->query($sql);
395:     $db->nextRecord();
396: 
397:     $idclient   = $db->f("idclient");
398:     $idlay      = $db->f("idlay");
399:     //$new_idtpl  = $db->nextid($cfg["tab"]["tpl"]);
400: 
401:     $name       = sprintf(i18n("%s (Copy)"), $db->f("name"));
402:     $descr      = $db->f("description");
403:     $author     = $auth->auth["uname"];
404:     $created    = date('Y-m-d H:i:s');
405:     $lastmod    = date('Y-m-d H:i:s');
406: 
407:     $idtpl_conf = $db->f("idtplcfg");
408:     if ($idtpl_conf) {
409:         // after inserted con_template, we have to update idptl
410:         $templateConf = array('idtpl'=>0, 'status'=>0, 'author'=>$author, 'created'=>$created);
411:         $db->insert($cfg["tab"]["tpl_conf"], $templateConf);
412:         $new_idtpl_conf = $db->getLastInsertedId($cfg["tab"]["tpl_conf"]);
413:     }
414: 
415:     $sql = "INSERT INTO
416:                 ".$cfg["tab"]["tpl"]."
417:                 (idclient, idlay, ".($idtpl_conf?'idtplcfg,':'')." name, description, deletable,author, created, lastmodified)
418:             VALUES
419:                 ('".cSecurity::toInteger($idclient)."', '".cSecurity::toInteger($idlay)."', ".($idtpl_conf?"'".cSecurity::toInteger($new_idtpl_conf)."', ":'')." '".cSecurity::escapeDB($name, $db)."',
420:                  '".cSecurity::escapeDB($descr, $db)."', '1', '".cSecurity::escapeDB($author, $db)."', '".cSecurity::escapeDB($created, $db)."', '".cSecurity::escapeDB($lastmod, $db)."')";
421:     $db->query($sql);
422:     $new_idtpl = $db->getLastInsertedId($cfg["tab"]["tpl"]);
423: 
424:     // update template_conf, set idtpl width right value.
425:     $db->update($cfg["tab"]["tpl_conf"], array('idtpl'=>$new_idtpl), array('idtplcfg'=>$new_idtpl_conf));
426: 
427:     $a_containers = array();
428: 
429:     $sql = "SELECT
430:                 *
431:             FROM
432:                 ".$cfg["tab"]["container"]."
433:             WHERE
434:                 idtpl = '".cSecurity::toInteger($idtpl)."'
435:             ORDER BY
436:                 number";
437: 
438:     $db->query($sql);
439: 
440:     while ($db->nextRecord()) {
441:         $a_containers[$db->f("number")] = $db->f("idmod");
442:     }
443: 
444:     foreach ($a_containers as $key => $value) {
445: 
446:         //$nextid = $db->nextid($cfg["tab"]["container"]);
447: 
448:         $sql = "INSERT INTO ".$cfg["tab"]["container"]."
449:                 (idtpl, number, idmod) VALUES ('".cSecurity::toInteger($new_idtpl)."', '".cSecurity::toInteger($key)."', '".cSecurity::toInteger($value)."')";
450: 
451:         $db->query($sql);
452: 
453:     }
454: 
455:     //modified (added) 2008-06-30 timo.trautmann added fix module settings were also copied
456:     if ($idtpl_conf) {
457:         $a_container_cfg = array();
458:         $sql = "SELECT
459:                        *
460:                  FROM
461:                        ".$cfg["tab"]["container_conf"]."
462:                  WHERE
463:                        idtplcfg = '".cSecurity::toInteger($idtpl_conf)."'
464:                  ORDER BY
465:                        number";
466: 
467:         $db->query($sql);
468: 
469:         while ($db->nextRecord()) {
470:            $a_container_cfg[$db->f("number")] = $db->f("container");
471:         }
472: 
473:         foreach ($a_container_cfg as $key => $value) {
474: 
475: 
476: 
477:            $sql = "INSERT INTO ".$cfg["tab"]["container_conf"]."
478:                        (idtplcfg, number, container) VALUES
479:                        ( '".cSecurity::toInteger($new_idtpl_conf)."', '".cSecurity::escapeDB($key, $db)."', '".cSecurity::escapeDB($value, $db)."')";
480: 
481:            $db->query($sql);
482: 
483:         }
484:     }
485:     //modified (added) 2008-06-30 end
486: 
487:     cInclude("includes", "functions.rights.php");
488:     copyRightsForElement("tpl", $idtpl, $new_idtpl);
489: 
490:     return $new_idtpl;
491: 
492: }
493: 
494: /**
495:  * Checks if a template is in use
496:  *
497:  * @param int $idtpl Template ID
498:  *
499:  * @return bool is template in use
500:  */
501: function tplIsTemplateInUse($idtpl) {
502: 
503:     global $cfg, $client, $lang;
504: 
505:     $db = cRegistry::getDb();
506:     // Check categorys
507:     $sql = "SELECT
508:                    b.idcatlang, b.name, b.idlang, b.idcat
509:             FROM
510:                 ".$cfg["tab"]["cat"]." AS a,
511:                 ".$cfg["tab"]["cat_lang"]." AS b
512:             WHERE
513:                 a.idclient  = '".cSecurity::toInteger($client)."' AND
514:                 a.idcat     = b.idcat AND
515:                 b.idtplcfg  IN (SELECT idtplcfg FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtpl = '".$idtpl."')
516:             ORDER BY b.idlang ASC, b.name ASC ";
517:     $db->query($sql);
518:     if ($db->numRows() > 0) {
519:         return true;
520:     }
521: 
522:     // Check articles
523:     $sql = "SELECT
524:                    b.idartlang, b.title, b.idlang, b.idart
525:             FROM
526:                 ".$cfg["tab"]["art"]." AS a,
527:                 ".$cfg["tab"]["art_lang"]." AS b
528:             WHERE
529:                 a.idclient  = '".cSecurity::toInteger($client)."' AND
530:                 a.idart     = b.idart AND
531:                 b.idtplcfg IN (SELECT idtplcfg FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtpl = '".$idtpl."')
532:             ORDER BY b.idlang ASC, b.title ASC ";
533: 
534:     $db->query($sql);
535: 
536:     if ($db->numRows() > 0) {
537:         return true;
538:     }
539: 
540:     return false;
541: 
542: }
543: 
544: /**
545:  * Get used datas if a template is in use
546:  *
547:  * @param int $idtpl Template ID
548:  *
549:  * @return array - category name, article name
550:  */
551: function tplGetInUsedData($idtpl) {
552: 
553:     global $cfg, $client, $lang;
554: 
555:     $db = cRegistry::getDb();
556: 
557:     $aUsedData = array();
558: 
559:     // Check categorys
560:     $sql = "SELECT
561:                    b.idcatlang, b.name, b.idlang, b.idcat
562:             FROM
563:                 ".$cfg["tab"]["cat"]." AS a,
564:                 ".$cfg["tab"]["cat_lang"]." AS b
565:             WHERE
566:                 a.idclient  = '".cSecurity::toInteger($client)."' AND
567:                 a.idcat     = b.idcat AND
568:                 b.idtplcfg  IN (SELECT idtplcfg FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtpl = '".$idtpl."')
569:             ORDER BY b.idlang ASC, b.name ASC ";
570:     $db->query($sql);
571:     if ($db->numRows() > 0) {
572:         while ($db->nextRecord()) {
573:             $aUsedData['cat'][] = array(
574:             'name' => $db->f('name'),
575:             'lang' => $db->f('idlang'),
576:             'idcat' => $db->f('idcat'),
577:             );
578:         }
579:     }
580: 
581:     // Check articles
582:     $sql = "SELECT
583:                    b.idartlang, b.title, b.idlang, b.idart
584:             FROM
585:                 ".$cfg["tab"]["art"]." AS a,
586:                 ".$cfg["tab"]["art_lang"]." AS b
587:             WHERE
588:                 a.idclient  = '".cSecurity::toInteger($client)."' AND
589:                 a.idart     = b.idart AND
590:                 b.idtplcfg IN (SELECT idtplcfg FROM ".$cfg["tab"]["tpl_conf"]." WHERE idtpl = '".$idtpl."')
591:             ORDER BY b.idlang ASC, b.title ASC ";
592: 
593:     $db->query($sql);
594: 
595:     if ($db->numRows() > 0) {
596:         while ($db->nextRecord()) {
597:             $aUsedData['art'][] = array(
598:             'title' => $db->f('title'),
599:             'lang' => $db->f('idlang'),
600:             'idart' => $db->f('idart'),
601:             );
602:         }
603:     }
604: 
605:     return $aUsedData;
606: 
607: }
608: 
609: /**
610:  * Copies a complete template configuration
611:  *
612:  * @param int $idtplcfg Template Configuration ID
613:  *
614:  * @return int new template configuration ID
615:  *
616:  */
617: function tplcfgDuplicate ($idtplcfg)
618: {
619:     global $cfg;
620: 
621:     $db = cRegistry::getDb();
622:     $db2 = cRegistry::getDb();
623: 
624:     $sql = "SELECT
625:                 idtpl, status, author, created, lastmodified
626:             FROM
627:                 ".$cfg["tab"]["tpl_conf"]."
628:             WHERE
629:                 idtplcfg = '".cSecurity::toInteger($idtplcfg)."'";
630: 
631:     $db->query($sql);
632: 
633:     if ($db->nextRecord())
634:     {
635:         //$newidtplcfg = $db2->nextid($cfg["tab"]["tpl_conf"]);
636:         $idtpl = $db->f("idtpl");
637:         $status = $db->f("status");
638:         $author = $db->f("author");
639:         $created = $db->f("created");
640:         $lastmodified = $db->f("lastmodified");
641: 
642:         $sql = "INSERT INTO
643:                 ".$cfg["tab"]["tpl_conf"]."
644:                 (idtpl, status, author, created, lastmodified)
645:                 VALUES
646:                 ('".cSecurity::toInteger($idtpl)."', '".cSecurity::toInteger($status)."', '".cSecurity::escapeDB($author, $db2)."',
647:                 '".cSecurity::escapeDB($created, $db2)."', '".cSecurity::escapeDB($lastmodified, $db2)."')";
648: 
649:         $db2->query($sql);
650:         $newidtplcfg = $db2->getLastInsertedId($cfg["tab"]["tpl_conf"]);
651: 
652:         /* Copy container configuration */
653:         $sql = "SELECT
654:                     number, container
655:                 FROM
656:                     ".$cfg["tab"]["container_conf"]."
657:                 WHERE idtplcfg = '".cSecurity::toInteger($idtplcfg)."'";
658: 
659:         $db->query($sql);
660: 
661:         while ($db->nextRecord())
662:         {
663:             //$newidcontainerc = $db2->nextid($cfg["tab"]["container_conf"]);
664:             $number = $db->f("number");
665:             $container = $db->f("container");
666: 
667:             $sql = "INSERT INTO
668:                     ".$cfg["tab"]["container_conf"]."
669:                     ( idtplcfg, number, container)
670:                     VALUES
671:                     ('".cSecurity::toInteger($newidtplcfg)."', '".cSecurity::toInteger($number)."', '".cSecurity::escapeDB($container, $db2)."')";
672:             $db2->query($sql);
673:         }
674:     }
675: 
676:     return ($newidtplcfg);
677: 
678: }
679: 
680: /*
681:  * tplAutoFillModules
682:  *
683:  * This function fills in modules automatically using this logic:
684:  *
685:  * - If the container mode is fixed, insert the named module (if exists)
686:  * - If the container mode is mandatory, insert the "default" module (if exists)
687:  *
688:  * TODO: The default module is only inserted in mandatory mode if the container
689:  *       is empty. We need a better logic for handling "changes".
690:  */
691: 
692: function tplAutoFillModules ($idtpl)
693: {
694:     global $cfg;
695:     global $db_autofill;
696:     global $containerinf;
697:     global $_autoFillcontainerCache;
698: 
699:     if (!is_object($db_autofill))
700:     {
701:         $db_autofill = cRegistry::getDb();
702:     }
703: 
704:     $sql = "SELECT idlay FROM ".$cfg["tab"]["tpl"]." WHERE idtpl = '".cSecurity::toInteger($idtpl)."'";
705:     $db_autofill->query($sql);
706: 
707:     if (!$db_autofill->nextRecord())
708:     {
709:         return false;
710:     }
711: 
712:     $idlay = $db_autofill->f("idlay");
713: 
714:     if (!(is_array($containerinf) && array_key_exists($idlay, $containerinf) && array_key_exists($idlay, $_autoFillcontainerCache)))
715:     {
716:         tplPreparseLayout($idlay);
717:         $_autoFillcontainerCache[$idlay] = tplBrowseLayoutForContainers($idlay);
718:     }
719: 
720:     $a_container = explode("&",$_autoFillcontainerCache[$idlay]);
721: 
722:     $db = cRegistry::getDb();
723: 
724:     foreach ($a_container as $container)
725:     {
726:         switch ($containerinf[$idlay][$container]["mode"])
727:         {
728:             /* Fixed mode */
729:             case "fixed":
730:             if ($containerinf[$idlay][$container]["default"] != "")
731:             {
732:                 $sql =     "SELECT idmod FROM ".$cfg["tab"]["mod"]
733:                         ." WHERE name = '".
734:                         cSecurity::escapeDB($containerinf[$idlay][$container]["default"], $db_autofill)."'";
735: 
736:                 $db_autofill->query($sql);
737: 
738:                 if ($db_autofill->nextRecord())
739:                 {
740:                     $idmod = $db_autofill->f("idmod");
741: 
742: 
743:                     $sql = "SELECT idcontainer FROM ".$cfg["tab"]["container"]." WHERE idtpl = '".cSecurity::toInteger($idtpl)."' AND number = '".cSecurity::toInteger($container)."'";
744: 
745:                     $db_autofill->query($sql);
746: 
747:                     if ($db_autofill->nextRecord())
748:                     {
749:                         $sql =     "UPDATE ".$cfg["tab"]["container"].
750:                                 " SET idmod = '".cSecurity::toInteger($idmod)."' WHERE idtpl = '".cSecurity::toInteger($idtpl)."'".
751:                                 " AND number = '".cSecurity::toInteger($container)."' AND ".
752:                                 " idcontainer = '".cSecurity::toInteger($db_autofill->f("idcontainer"))."'";
753:                         $db_autofill->query($sql);
754:                     } else {
755:                         $sql =     "INSERT INTO ".$cfg["tab"]["container"].
756:                                   " (idtpl, number, idmod) ".
757:                                   " VALUES ( ".
758:                                   " '$idtpl', '$container', '$idmod')";
759:                         $db_autofill->query($sql);
760:                     }
761:                 }
762:             }
763: 
764: 
765:             case "mandatory":
766: 
767:             if ($containerinf[$idlay][$container]["default"] != "")
768:             {
769:                 $sql =     "SELECT idmod FROM ".$cfg["tab"]["mod"]
770:                         ." WHERE name = '".
771:                         cSecurity::escapeDB($containerinf[$idlay][$container]["default"], $db)."'";
772: 
773:                 $db_autofill->query($sql);
774: 
775:                 if ($db_autofill->nextRecord())
776:                 {
777:                     $idmod = $db_autofill->f("idmod");
778: 
779: 
780:                     $sql =     "SELECT idcontainer, idmod FROM ".$cfg["tab"]["container"]
781:                             ." WHERE idtpl = '".cSecurity::toInteger($idtpl)."' AND number = '".cSecurity::toInteger($container)."'";
782: 
783:                     $db_autofill->query($sql);
784: 
785:                     if ($db_autofill->nextRecord())
786:                     {
787: 
788:                     } else {
789:                         $sql =     "INSERT INTO ".$cfg["tab"]["container"].
790:                                   " (idtpl, number, idmod) ".
791:                                   " VALUES ( ".
792:                                   " '".cSecurity::toInteger($idtpl)."', '".cSecurity::toInteger($container)."', '".cSecurity::toInteger($idmod)."')";
793:                         $db_autofill->query($sql);
794:                     }
795:                 }
796:             }
797:         }
798:     }
799: 
800: }
801: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0