Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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:     global $db, $sess, $auth, $client, $cfg;
 25: 
 26:     $author = (string) $auth->auth['uname'];
 27: 
 28:     //******** entry in 'tpl'-table ***************
 29: #    set_magic_quotes_gpc($name);
 30: #    set_magic_quotes_gpc($description);
 31: 
 32:     $template = new cApiTemplate();
 33:     $template->loadByMany(array('idclient' => $client, 'name' => $name));
 34:     if ($template->isLoaded() && $template->get('idtpl') != $idtpl) {
 35:         cRegistry::addErrorMessage(i18n("Template name already exists"));
 36:         return -1;
 37:     }
 38: 
 39:     if (!$idtpl) {
 40:         // Insert new entry in the Template table
 41:         $templateColl = new cApiTemplateCollection();
 42:         $template = $templateColl->create($client, $idlay, 0, $name, $description, 1, 0, 0);
 43:         $idtpl = $template->get('idtpl');
 44: 
 45:         // Insert new entry in the Template Conf table
 46:         $templateConfColl = new cApiTemplateConfigurationCollection();
 47:         $templateConf = $templateConfColl->create($idtpl);
 48:         $idtplcfg = $templateConf->get('idtplcfg');
 49: 
 50:         // Update new idtplconf
 51:         $template->set('idtplcfg', $idtplcfg);
 52:         $template->store();
 53: 
 54:         // Set correct rights for element
 55:         cInclude('includes', 'functions.rights.php');
 56:         createRightsForElement('tpl', $idtpl);
 57:     } else {
 58: 
 59:         // Define lastmodified variable with actual date
 60:         $lastmodified = date('Y-m-d H:i:s');
 61: 
 62:         // Update existing entry in the Template table
 63:         $template = new cApiTemplate($idtpl);
 64:         $template->set('name', $name);
 65:         $template->set('description', $description);
 66:         $template->set('idlay', $idlay);
 67:         $template->set('author', $author);
 68:         $template->set('lastmodified', $lastmodified);
 69:         $template->store();
 70: 
 71:         if (is_array($c)) {
 72:             // Delete all container assigned to this template
 73:             $containerColl = new cApiContainerCollection();
 74:             $containerColl->clearAssignments($idtpl);
 75: 
 76:             foreach ($c as $idcontainer => $dummyval) {
 77:                 $containerColl2 = new cApiContainerCollection();
 78:                 $containerColl2->create($idtpl, $idcontainer, $c[$idcontainer]);
 79:             }
 80:         }
 81: 
 82:         // Generate code
 83:         conGenerateCodeForAllartsUsingTemplate($idtpl);
 84:     }
 85: 
 86:     if ($default == 1) {
 87:         $sql = "UPDATE " . $cfg["tab"]["tpl"] . " SET defaulttemplate = 0 WHERE idclient = " . cSecurity::toInteger($client) . " AND idtpl != " . cSecurity::toInteger($template->get('idtpl'));
 88:         $db->query($sql);
 89: 
 90:         $template->set('defaulttemplate', 1);
 91:         $template->store();
 92:     } else {
 93:         $template->set('defaulttemplate', 0);
 94:         $template->store();
 95:     }
 96: 
 97:     //******** if layout is changed stay at 'tpl_edit' otherwise go to 'tpl'
 98:     //if ($changelayout != 1) {
 99:     //   $url = $sess->url("main.php?area=tpl_edit&idtpl=$idtpl&frame=4&blubi=blubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
100:     //  header("location: $url");
101:     //}
102: 
103:     return $idtpl;
104: }
105: 
106: /**
107:  * Delete a template
108:  *
109:  * @param int $idtpl ID of the template to duplicate
110:  */
111: function tplDeleteTemplate($idtpl) {
112: 
113:     global $db, $client, $lang, $cfg, $area_tree, $perm;
114: 
115:     $sql = "DELETE FROM " . $cfg["tab"]["tpl"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
116:     $db->query($sql);
117: 
118:     /* JL 160603 : Delete all unnecessary entries */
119: 
120:     $sql = "DELETE FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
121:     $db->query($sql);
122: 
123:     $idsToDelete = array();
124:     $sql = "SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
125:     $db->query($sql);
126:     while ($db->nextRecord()) {
127:         $idsToDelete[] = $db->f("idtplcfg");
128:     }
129: 
130:     foreach ($idsToDelete as $id) {
131:         $sql = "DELETE FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtplcfg = '" . cSecurity::toInteger($id) . "'";
132:         $db->query($sql);
133: 
134:         $sql = "DELETE FROM " . $cfg["tab"]["container_conf"] . " WHERE idtplcfg = '" . cSecurity::toInteger($id) . "'";
135:         $db->query($sql);
136:     }
137: 
138:     cInclude("includes", "functions.rights.php");
139:     deleteRightsForElement("tpl", $idtpl);
140: }
141: 
142: /**
143:  * Browse a specific layout for containers
144:  *
145:  * @param int $idtpl Layout number to browse
146:  *
147:  * @return string &-seperated String of all containers
148:  */
149: function tplBrowseLayoutForContainers($idlay) {
150:     global $db, $cfg, $containerinf, $lang;
151: 
152:     $layoutInFile = new cLayoutHandler($idlay, '', $cfg, $lang);
153:     $code = $layoutInFile->getLayoutCode();
154: 
155:     $containerNumbers = array();
156:     $returnStr = '';
157: 
158:     preg_match_all("/CMS_CONTAINER\[([0-9]*)\]/", $code, $containerMatches);
159:     $posBody = stripos($code, '<body>');
160:     $codeBeforeHeader = substr($code, 0, $posBody);
161: 
162:     foreach ($containerMatches[1] as $value) {
163:         if (preg_match("/CMS_CONTAINER\[$value\]/", $codeBeforeHeader)) {
164:             $containerinf[$idlay][$value]["is_body"] = false;
165:         } else {
166:             $containerinf[$idlay][$value]["is_body"] = true;
167:         }
168:     }
169: 
170:     if (is_array($containerinf[$idlay])) {
171:         foreach ($containerinf[$idlay] as $key => $value) {
172:             $containerMatches[1][] = $key;
173:         }
174:     }
175: 
176:     foreach ($containerMatches[1] as $value) {
177:         if (!in_array($value, $containerNumbers)) {
178:             $containerNumbers[] = $value;
179:         }
180:     }
181:     asort($containerNumbers);
182: 
183:     $returnStr = implode('&', $containerNumbers);
184: 
185:     return $returnStr;
186: }
187: 
188: /**
189:  * Wrapper for tplPreparseLayout() and tplBrowseLayoutForContainers().
190:  * Calls both functions to get the container numbers from layout and return
191:  * the list of found container numbers.
192:  * @param  int  $idlay
193:  * @return array
194:  */
195: function tplGetContainerNumbersInLayout($idlay) {
196:     $containerNumbers = array();
197: 
198:     tplPreparseLayout($idlay);
199:     $containerNumbersStr = tplBrowseLayoutForContainers($idlay);
200:     if (!empty($containerNumbersStr)) {
201:         $containerNumbers = explode('&', $containerNumbersStr);
202:     }
203: 
204:     return $containerNumbers;
205: }
206: 
207: /**
208:  * Retrieve the container name
209:  *
210:  * @param int $idtpl Layout number to browse
211:  * @param int $container Container number
212:  *
213:  * @return string Container name
214:  */
215: function tplGetContainerName($idlay, $container) {
216:     global $db, $cfg, $containerinf;
217: 
218:     if (is_array($containerinf[$idlay])) {
219:         if (array_key_exists($container, $containerinf[$idlay])) {
220:             return $containerinf[$idlay][$container]["name"];
221:         }
222:     }
223: }
224: 
225: /**
226:  * Retrieve the container mode
227:  *
228:  * @param int $idtpl Layout number to browse
229:  * @param int $container Container number
230:  *
231:  * @return string Container name
232:  */
233: function tplGetContainerMode($idlay, $container) {
234:     global $db, $cfg, $containerinf;
235: 
236:     if (is_array($containerinf[$idlay])) {
237:         if (array_key_exists($container, $containerinf[$idlay])) {
238:             return $containerinf[$idlay][$container]["mode"];
239:         }
240:     }
241: }
242: 
243: /**
244:  * Retrieve the allowed container types
245:  *
246:  * @param int $idtpl Layout number to browse
247:  * @param int $container Container number
248:  *
249:  * @return array Allowed container types
250:  */
251: function tplGetContainerTypes($idlay, $container) {
252:     global $db, $cfg, $containerinf;
253: 
254:     if (is_array($containerinf[$idlay])) {
255:         if (array_key_exists($container, $containerinf[$idlay])) {
256:             if ($containerinf[$idlay][$container]["types"] != "") {
257:                 $list = explode(",", $containerinf[$idlay][$container]["types"]);
258: 
259:                 foreach ($list as $key => $value) {
260:                     $list[$key] = trim($value);
261:                 }
262:                 return $list;
263:             }
264:         }
265:     }
266: }
267: 
268: /**
269:  * Retrieve the default module
270:  *
271:  * @param int $idtpl Layout number to browse
272:  * @param int $container Container number
273:  *
274:  * @return array Allowed container types
275:  */
276: function tplGetContainerDefault($idlay, $container) {
277:     global $db, $cfg, $containerinf;
278: 
279:     if (is_array($containerinf[$idlay])) {
280:         if (array_key_exists($container, $containerinf[$idlay])) {
281:             return $containerinf[$idlay][$container]["default"];
282:         }
283:     }
284: }
285: 
286: /**
287:  * Preparse the layout for caching purposes
288:  *
289:  * @param int $idtpl Layout number to browse
290:  */
291: function tplPreparseLayout($idlay) {
292:     global $db, $cfg, $containerinf, $lang;
293: 
294:     $layoutInFile = new cLayoutHandler($idlay, "", $cfg, $lang);
295:     $code = $layoutInFile->getLayoutCode();
296: 
297:     $parser = new HtmlParser($code);
298:     $bIsBody = false;
299:     while ($parser->parse()) {
300:         if (strtolower($parser->iNodeName) == 'body') {
301:             $bIsBody = true;
302:         }
303: 
304:         if ($parser->iNodeName == "container" && $parser->iNodeType == HtmlParser::NODE_TYPE_ELEMENT) {
305:             $idcontainer = $parser->iNodeAttributes["id"];
306: 
307:             $mode = $parser->iNodeAttributes["mode"];
308: 
309:             if ($mode == "") {
310:                 $mode = "optional";
311:             }
312: 
313:             $containerinf[$idlay][$idcontainer]["name"] = $parser->iNodeAttributes["name"];
314:             $containerinf[$idlay][$idcontainer]["mode"] = $mode;
315:             $containerinf[$idlay][$idcontainer]["default"] = $parser->iNodeAttributes["default"];
316:             $containerinf[$idlay][$idcontainer]["types"] = $parser->iNodeAttributes["types"];
317:             $containerinf[$idlay][$idcontainer]["is_body"] = $bIsBody;
318:         }
319:     }
320: }
321: 
322: /**
323:  * Duplicate a template
324:  *
325:  * @param int $idtpl ID of the template to duplicate
326:  *
327:  * @return  int  ID of the duplicated template
328:  */
329: function tplDuplicateTemplate($idtpl) {
330:     global $db, $client, $lang, $cfg, $sess, $auth;
331: 
332:     $idtpl = cSecurity::toInteger($idtpl);
333:     $template = new cApiTemplate($idtpl);
334: 
335:     $newidtplcfg = 0;
336:     $idtplcfg = cSecurity::toInteger($template->get('idtplcfg'));
337:     if ($idtplcfg) {
338:         // NB: after inserted new template, we have to update idptl
339:         $templateConfigColl = new cApiTemplateConfigurationCollection();
340:         $templateConfig = $templateConfigColl->create(0);
341:         $newidtplcfg = cSecurity::toInteger($templateConfig->get('idtplcfg'));
342:     }
343: 
344:     // Copy template
345:     $templateColl = new cApiTemplateCollection();
346:     $newTemplate = $templateColl->copyItem($template, array(
347:         'idtplcfg' => $newidtplcfg,
348:         'name' => sprintf(i18n("%s (Copy)"), $template->get('name')),
349:         'author' => cSecurity::toString($auth->auth['uname']),
350:         'created' => date('Y-m-d H:i:s'),
351:         'lastmodified' => date('Y-m-d H:i:s'),
352:         'defaulttemplate' => 0
353:     ));
354:     $newidtpl = cSecurity::toInteger($newTemplate->get('idtpl'));
355: 
356:     // Update template configuration, set idtpl width new value
357:     if ($idtplcfg) {
358:         $templateConfig->set('idtpl', $newidtpl);
359:         $templateConfig->store();
360:     }
361: 
362:     // Copy container from old template to new template
363:     $containerColl = new cApiContainerCollection();
364:     $containerColl->select('idtpl = ' . $idtpl . ' ORDER BY number');
365:     while (($container = $containerColl->next()) !== false) {
366:         $containerColl2 = new cApiContainerCollection();
367:         $containerColl2->copyItem($container, array('idtpl' => $newidtpl));
368:     }
369: 
370:     // Copy container configuration from old template configuration to new template configuration
371:     if ($idtplcfg) {
372:         $containerConfigColl = new cApiContainerConfigurationCollection();
373:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
374:         while (($containerConfig = $containerConfigColl->next()) !== false) {
375:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
376:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
377:         }
378:     }
379: 
380:     cInclude('includes', 'functions.rights.php');
381:     copyRightsForElement('tpl', $idtpl, $newidtpl);
382: 
383:     return $newidtpl;
384: }
385: 
386: /**
387:  * Checks if a template is in use
388:  *
389:  * @param int $idtpl Template ID
390:  *
391:  * @return bool is template in use
392:  */
393: function tplIsTemplateInUse($idtpl) {
394:     global $cfg, $client, $lang;
395: 
396:     $db = cRegistry::getDb();
397:     // Check categorys
398:     $sql = "SELECT
399:                    b.idcatlang, b.name, b.idlang, b.idcat
400:             FROM
401:                 " . $cfg["tab"]["cat"] . " AS a,
402:                 " . $cfg["tab"]["cat_lang"] . " AS b
403:             WHERE
404:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
405:                 a.idcat     = b.idcat AND
406:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
407:             ORDER BY b.idlang ASC, b.name ASC ";
408:     $db->query($sql);
409:     if ($db->numRows() > 0) {
410:         return true;
411:     }
412: 
413:     // Check articles
414:     $sql = "SELECT
415:                    b.idartlang, b.title, b.idlang, b.idart
416:             FROM
417:                 " . $cfg["tab"]["art"] . " AS a,
418:                 " . $cfg["tab"]["art_lang"] . " AS b
419:             WHERE
420:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
421:                 a.idart     = b.idart AND
422:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
423:             ORDER BY b.idlang ASC, b.title ASC ";
424: 
425:     $db->query($sql);
426: 
427:     if ($db->numRows() > 0) {
428:         return true;
429:     }
430: 
431:     return false;
432: }
433: 
434: /**
435:  * Get used datas if a template is in use
436:  *
437:  * @param int $idtpl Template ID
438:  *
439:  * @return array - category name, article name
440:  */
441: function tplGetInUsedData($idtpl) {
442:     global $cfg, $client, $lang;
443: 
444:     $db = cRegistry::getDb();
445: 
446:     $aUsedData = array();
447: 
448:     // Check categorys
449:     $sql = "SELECT
450:                    b.idcatlang, b.name, b.idlang, b.idcat
451:             FROM
452:                 " . $cfg["tab"]["cat"] . " AS a,
453:                 " . $cfg["tab"]["cat_lang"] . " AS b
454:             WHERE
455:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
456:                 a.idcat     = b.idcat AND
457:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
458:             ORDER BY b.idlang ASC, b.name ASC ";
459:     $db->query($sql);
460:     if ($db->numRows() > 0) {
461:         while ($db->nextRecord()) {
462:             $aUsedData['cat'][] = array(
463:                 'name' => $db->f('name'),
464:                 'lang' => $db->f('idlang'),
465:                 'idcat' => $db->f('idcat'),
466:             );
467:         }
468:     }
469: 
470:     // Check articles
471:     $sql = "SELECT
472:                    b.idartlang, b.title, b.idlang, b.idart
473:             FROM
474:                 " . $cfg["tab"]["art"] . " AS a,
475:                 " . $cfg["tab"]["art_lang"] . " AS b
476:             WHERE
477:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
478:                 a.idart     = b.idart AND
479:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
480:             ORDER BY b.idlang ASC, b.title ASC ";
481: 
482:     $db->query($sql);
483: 
484:     if ($db->numRows() > 0) {
485:         while ($db->nextRecord()) {
486:             $aUsedData['art'][] = array(
487:                 'title' => $db->f('title'),
488:                 'lang' => $db->f('idlang'),
489:                 'idart' => $db->f('idart'),
490:             );
491:         }
492:     }
493: 
494:     return $aUsedData;
495: }
496: 
497: /**
498:  * Copies a complete template configuration
499:  *
500:  * @param int $idtplcfg Template Configuration ID
501:  * @return int new template configuration ID
502:  */
503: function tplcfgDuplicate($idtplcfg) {
504:     global $auth;
505: 
506:     $templateConfig = new cApiTemplateConfiguration(cSecurity::toInteger($idtplcfg));
507:     if (!$templateConfig->isLoaded()) {
508:         return 0;
509:     }
510: 
511:     // Copy template configuration
512:     $templateConfigColl = new cApiTemplateConfigurationCollection();
513:     $newTemplateConfig = $templateConfigColl->copyItem($templateConfig, array(
514:         'author' => (string) $auth->auth['uname'],
515:         'created' => date('Y-m-d H:i:s'),
516:         'lastmodified' => date('Y-m-d H:i:s'),
517:     ));
518:     $newidtplcfg = $newTemplateConfig->get('idtplcfg');
519: 
520:     // Copy container configuration from old template configuration to new template configuration
521:     if ($idtplcfg) {
522:         $containerConfigColl = new cApiContainerConfigurationCollection();
523:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
524:         while (($containerConfig = $containerConfigColl->next()) !== false) {
525:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
526:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
527:         }
528:     }
529: 
530:     return $newidtplcfg;
531: }
532: 
533: /*
534:  * This function fills in modules automatically using this logic:
535:  *
536:  * - If the container mode is fixed, insert the named module (if exists)
537:  * - If the container mode is mandatory, insert the "default" module (if exists)
538:  *
539:  * TODO: The default module is only inserted in mandatory mode if the container
540:  *       is empty. We need a better logic for handling "changes".
541:  */
542: 
543: function tplAutoFillModules($idtpl) {
544:     global $cfg, $db_autofill, $containerinf, $_autoFillcontainerCache;
545: 
546:     if (!is_object($db_autofill)) {
547:         $db_autofill = cRegistry::getDb();
548:     }
549: 
550:     $sql = "SELECT idlay FROM " . $cfg["tab"]["tpl"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
551:     $db_autofill->query($sql);
552: 
553:     if (!$db_autofill->nextRecord()) {
554:         return false;
555:     }
556: 
557:     $idlay = $db_autofill->f("idlay");
558: 
559:     if (!(is_array($containerinf) && array_key_exists($idlay, $containerinf) && array_key_exists($idlay, $_autoFillcontainerCache))) {
560:         $_autoFillcontainerCache[$idlay] = tplGetContainerNumbersInLayout($idlay);
561:     }
562: 
563:     $containerNumbers = $_autoFillcontainerCache[$idlay];
564: 
565:     $db = cRegistry::getDb();
566: 
567:     foreach ($containerNumbers as $containerNr) {
568:         $currContainerInfo = $containerinf[$idlay][$containerNr];
569: 
570:         switch ($currContainerInfo["mode"]) {
571:             /* Fixed mode */
572:             case "fixed":
573:                 if ($currContainerInfo["default"] != "") {
574:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"] . " WHERE name = '" . $db->escape($currContainerInfo["default"]) . "'";
575:                     $db_autofill->query($sql);
576: 
577:                     if ($db_autofill->nextRecord()) {
578:                         $idmod = $db_autofill->f("idmod");
579: 
580:                         $sql = "SELECT idcontainer FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($containerNr) . "'";
581:                         $db_autofill->query($sql);
582: 
583:                         if ($db_autofill->nextRecord()) {
584:                             $sql = "UPDATE " . $cfg["tab"]["container"] .
585:                                     " SET idmod = '" . cSecurity::toInteger($idmod) . "' WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'" .
586:                                     " AND number = '" . cSecurity::toInteger($containerNr) . "' AND " .
587:                                     " idcontainer = '" . cSecurity::toInteger($db_autofill->f("idcontainer")) . "'";
588:                             $db_autofill->query($sql);
589:                         } else {
590:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] . " (idtpl, number, idmod) " .
591:                                     " VALUES ('$idtpl', '$containerNr', '$idmod')";
592:                             $db_autofill->query($sql);
593:                         }
594:                     }
595:                 }
596: 
597:             case "mandatory":
598: 
599:                 if ($currContainerInfo["default"] != "") {
600:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"] . " WHERE name = '" . $db->escape($currContainerInfo["default"]) . "'";
601:                     $db_autofill->query($sql);
602: 
603:                     if ($db_autofill->nextRecord()) {
604:                         $idmod = $db_autofill->f("idmod");
605: 
606:                         $sql = "SELECT idcontainer FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($containerNr) . "'";
607:                         $db_autofill->query($sql);
608: 
609:                         if ($db_autofill->nextRecord()) {
610:                             // donut
611:                         } else {
612:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] . " (idtpl, number, idmod) " .
613:                                     " VALUES ('" . cSecurity::toInteger($idtpl) . "', '" . cSecurity::toInteger($containerNr) . "', '" . cSecurity::toInteger($idmod) . "')";
614:                             $db_autofill->query($sql);
615:                         }
616:                     }
617:                 }
618:         }
619:     }
620: }
621: 
622: /**
623:  * Takes over send container configuration data, stores send data (via POST) by article
624:  * or template configuration in container configuration table.
625:  * @param int $idtpl
626:  * @param int  $idtplcfg
627:  * @param array $postData  Usually $_POST
628:  */
629: function tplProcessSendContainerConfiguration($idtpl, $idtplcfg, array $postData) {
630: 
631:     $containerColl = new cApiContainerCollection();
632:     $containerConfColl = new cApiContainerConfigurationCollection();
633:     $containerData = array();
634: 
635:     // Get all container numbers, loop through them and collect send container data
636:     $containerNumbers = $containerColl->getNumbersByTemplate($idtpl);
637:     foreach ($containerNumbers as $number) {
638:         $CiCMS_VAR = 'C' . $number . 'CMS_VAR';
639: 
640:         if (isset($postData[$CiCMS_VAR]) && is_array($postData[$CiCMS_VAR])) {
641:             if (!isset($containerData[$number])) {
642:                 $containerData[$number] = '';
643:             }
644:             foreach ($postData[$CiCMS_VAR] as $key => $value) {
645:                 $containerData[$number] = cApiContainerConfiguration::addContainerValue($containerData[$number], $key, $value);
646:             }
647:         }
648:     }
649: 
650:     // Update/insert in container_conf
651:     if (count($containerData) > 0) {
652:         // Delete all containers
653:         $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
654: 
655:         // Insert new containers
656:         foreach ($containerData as $col => $val) {
657:             $containerConfColl->create($idtplcfg, $col, $val);
658:         }
659:     }
660: 
661: }
662: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen