예제 #1
0
파일: module.php 프로젝트: Prescia/Prescia
 function runAction($action, $data, $silent = false, $mfo = false, $startedAt = "")
 {
     # mfo is "Mandatory Fields Ok", which removes the need to check them
     # returns TRUE or FALSE
     # check for auto_increment during insert on $parent->lastReturnCode
     if (is_object($action)) {
         $this->parent->errorControl->raise(126);
     }
     $this->parent->lastReturnCode = 0;
     unset($this->parent->storage['lastactiondata']);
     if (is_numeric($data)) {
         if ($action == CONS_ACTION_DELETE) {
             $id = $data;
             $data = array();
             $data[$this->keys[0]] = $id;
         } else {
             if (!$silent) {
                 $this->parent->errorControl->raise(187, $data, $this->name);
             }
             return false;
         }
     }
     if (count($this->plugins) > 0 && ($action == CONS_ACTION_UPDATE || $action == CONS_ACTION_INCLUDE || $action == CONS_ACTION_DELETE)) {
         foreach ($this->plugins as $pname) {
             if (!$this->parent->loadedPlugins[$pname]->edit_parse($action, $data)) {
                 if (!$silent) {
                     $this->parent->errorControl->raise(168, $pname, $this->name);
                 }
                 return false;
             }
         }
     }
     if (!$mfo) {
         $missing = $this->check_mandatory($data, $action);
         # returns a list of mandatory fields missing or invalid
         if (count($missing) > 0) {
             $this->parent->errorState = true;
             if (!$silent) {
                 $this->parent->errorControl->raise(127, implode(",", $missing), $this->name);
             }
             return false;
         }
     }
     $EnumPrunecache = array();
     switch ($action) {
         case CONS_ACTION_UPDATE:
             ###################################################### UPDATE ############################################
             $wS = "";
             # whereStruct
             $kA = array();
             # keyArray
             $haveAllKeys = $this->getKeys($wS, $kA, $data);
             // is it ok not to have all keys?
             # security
             if ($this->parent->safety && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100) {
                 $Owner = $this->parent->authControl->checkOwner($this, $kA);
                 // array with isOwner and isSameGroup
                 $this->parent->lockPermissions();
                 # Load permissions to this, in case something changed
                 if (!$this->parent->authControl->checkPermission($this, CONS_ACTION_UPDATE, $Owner, $data)) {
                     $this->parent->errorControl->raise(151, '', $this->name);
                     return false;
                 }
             }
             $this->parent->notifyEvent($this, CONS_ACTION_UPDATE, $data, $startedAt, true);
             # early notify
             $sql = "UPDATE " . $this->dbname . " SET ";
             $output = "";
             $outfield = false;
             foreach ($this->fields as $name => $field) {
                 if ($this->parent->safety && isset($field[CONS_XML_RESTRICT]) && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < $field[CONS_XML_RESTRICT] && !isset($field[CONS_XML_UPDATESTAMP])) {
                     # safety is on and this is a restricted field, while the user trying to change it does not have enough level
                     if (isset($data[$name])) {
                         $this->parent->errorControl->raise(145, $name, $this->name);
                     }
                     continue;
                 }
                 if ($name != $this->keys[0] && strpos($field[CONS_XML_SQL], "AUTO_INCREMENT") === false) {
                     # cannot change main key or auto_increment ones
                     $outfield = $this->sqlParameter(false, $data, $name, $field, $EnumPrunecache, false, $kA, $wS);
                     if ($outfield !== false) {
                         $output .= $name . "=" . $outfield . ",";
                     }
                 }
                 # if (not key)
             }
             #foreach
             unset($outfield);
             if ($output != "") {
                 # removes end ,
                 $output = substr($output, 0, strlen($output) - 1);
                 $sql .= $output . " WHERE " . $wS;
                 if (!$this->parent->dbo->simpleQuery($sql, $this->parent->debugmode)) {
                     $this->parent->errorState = true;
                     $lastError = $this->parent->dbo->log[count($this->parent->dbo->log) - 1];
                     if (strpos(strtolower($lastError), "duplicate") === false) {
                         if (!$silent) {
                             $this->parent->errorControl->raise(136, "", $this->name);
                         }
                     } else {
                         if (!$silent) {
                             $this->parent->errorControl->raise(137, "", $this->name);
                         }
                     }
                     return false;
                 } else {
                     $this->parent->notifyEvent($this, CONS_ACTION_UPDATE, $data, $startedAt);
                     # later notify
                     $this->parent->storage['lastactiondata'] =& $data;
                 }
             } else {
                 $this->parent->errorState = true;
                 if (!$silent) {
                     $this->parent->errorControl->raise(138, "", $this->name);
                 }
                 return false;
             }
             if (count($EnumPrunecache) != 0) {
                 $this->autoPrune($EnumPrunecache, $data);
             }
             return true;
             break;
         case CONS_ACTION_INCLUDE:
             ###################################################### INCLUDE ############################################
             if ($this->parent->safety) {
                 # checkPermission has this test but this is faster
                 if ($this->parent->safety && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100) {
                     $this->parent->lockPermissions();
                     if (!$this->parent->authControl->checkPermission($this, CONS_ACTION_INCLUDE, array(true, true, true, 0))) {
                         $this->parent->errorControl->raise(150, '', $this->name);
                         return false;
                         # cannot create even OWNED items
                     }
                 }
                 # can create items
             }
             # if this module have multiple key fields, there is no auto_increment IF there is an id (id created automatically w/o AI)
             if (count($this->keys) > 1 && $this->keys[0] == "id") {
                 $wheres = array();
                 foreach ($this->keys as $field) {
                     if ($field != "") {
                         if (!isset($data[$field])) {
                             # we need this parent data to create the id, but it's missing!
                             $this->parent->errorState = true;
                             if (!$silent) {
                                 $this->parent->errorControl->raise(139, $field, $this->name);
                             }
                             return false;
                         }
                         array_push($wheres, $field . "=\"" . $data[$field] . "\"");
                     }
                 }
                 # foreach
                 $sql = "SELECT MAX(id) FROM " . $this->dbname . (count($wheres) != 0 ? " WHERE " . implode(" AND ", $wheres) : "");
                 $id = $this->parent->dbo->fetch($sql, $this->parent->debugmode);
                 if (!$id) {
                     # suposes it was empty
                     $id = 1;
                 } else {
                     $id++;
                 }
                 $sql = "INSERT INTO " . $this->dbname . " SET id='{$id}',";
                 $data['id'] = $id;
             } else {
                 $id = false;
                 $sql = "INSERT INTO " . $this->dbname . " SET ";
             }
             $output = "";
             $hasAuto = "";
             $outfield = false;
             foreach ($this->fields as $name => $field) {
                 if ($this->parent->safety && isset($field[CONS_XML_RESTRICT]) && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < $field[CONS_XML_RESTRICT]) {
                     # safety is on and this is a restricted field, while the user trying to add it does not have enough level
                     # however while ADDING a field that is mandatory, if it has no default you can add
                     if (!isset($field[CONS_XML_MANDATORY]) || isset($field[CONS_XML_DEFAULT])) {
                         if (isset($data[$name])) {
                             $this->parent->errorControl->raise(145, $name, $this->name, 'not mandatory or default on add');
                         }
                         unset($data[$name]);
                     }
                 }
                 if (strpos(strtolower($field[CONS_XML_SQL]), "auto_increment") === false && !($this->keys[0] == "id" && $name == $this->keys[0] && count($this->keys) > 1)) {
                     # cannot change auto_increment or main key fields
                     $outfield = $this->sqlParameter(true, $data, $name, $field, $EnumPrunecache);
                     if ($outfield !== false) {
                         $output .= $name . "=" . $outfield . ",";
                     }
                     if ((!$outfield || !isset($data[$name]) || $data[$name] == '') && isset($field[CONS_XML_AUTOFILL]) && !isset($field[CONS_XML_DEFAULT])) {
                         if (isset($data[$field[CONS_XML_AUTOFILL]])) {
                             $data[$name] = $data[$field[CONS_XML_AUTOFILL]];
                             // if the autofill field is HTML and this is NOT, remove HTML
                             if ($field[CONS_XML_TIPO] == CONS_TIPO_TEXT && !isset($field[CONS_XML_HTML])) {
                                 if (isset($this->fields[$field[CONS_XML_AUTOFILL]][CONS_XML_HTML])) {
                                     $data[$name] = preg_replace("/(<)([^<>]*)(>)/", "", $data[$name]);
                                 }
                             }
                             $output .= $name . "=\"" . $data[$name] . "\",";
                         }
                     }
                 } else {
                     # if (not AutoIncrement)
                     $hasAuto = $name;
                 }
             }
             #foreach
             $id = 0;
             unset($outfield);
             if ($output != "") {
                 # removes end ,
                 $output = substr($output, 0, strlen($output) - 1);
                 $sql .= $output;
                 if (!$this->parent->dbo->simpleQuery($sql, $this->parent->debugmode)) {
                     $this->parent->errorState = true;
                     $lastError = $this->parent->dbo->log[count($this->parent->dbo->log) - 1];
                     if (strpos(strtolower($lastError), "duplicate") === false) {
                         if (!$silent) {
                             $this->parent->errorControl->raise(140, $lastError, $this->name);
                         }
                     } else {
                         if (!$silent) {
                             $this->parent->errorControl->raise(141, $lastError, $this->name);
                         }
                     }
                     return false;
                 } else {
                     # post processing ...
                     if ($this->keys[0] == "id") {
                         $id = $this->parent->dbo->insert_id();
                         if ($hasAuto != "") {
                             $data[$hasAuto] = $id;
                         } else {
                             $data['id'] = $id;
                         }
                     }
                     # check for uploads and urla
                     $wS = "";
                     $kA = array();
                     $this->getKeys($wS, $kA, $data);
                     foreach ($this->fields as $name => $field) {
                         if ($field[CONS_XML_TIPO] == CONS_TIPO_SERIALIZED) {
                             foreach ($field[CONS_XML_SERIALIZEDMODEL] as $exname => $exfield) {
                                 #--- serialized uploads
                                 if ($exfield[CONS_XML_TIPO] == CONS_TIPO_UPLOAD) {
                                     $upOk = $this->prepareUpload($name . "_" . $exname, $kA, $data);
                                     if ($upOk != 4 && $upOk != 0) {
                                         // 4 = nothing sent, 0 = sent and ok
                                         # not mandatory but failed, warn about it but do not abort
                                         if (!$silent) {
                                             $this->parent->errorControl->raise(200 + $upOk, $upOk, $this->name, $name . '_' . $exname);
                                         }
                                         //$this->deleteUploads($kA,$name."_".$exname,'',$name); // delete possible partial thumbnail process
                                         # so far, serialized uploads have no flag
                                         //} else if ($upOk == 0) {
                                         //	$this->parent->dbo->simpleQuery("UPDATE ".$this->dbname." SET $name='y' WHERE $wS");
                                     }
                                 }
                             }
                         }
                         if ($field[CONS_XML_TIPO] == CONS_TIPO_UPLOAD) {
                             #--- normal uploads
                             $upOk = $this->prepareUpload($name, $kA, $data);
                             if ($upOk != 0 && isset($field[CONS_XML_MANDATORY])) {
                                 # failed or didn't send upload but it's mandatory
                                 $this->parent->errorState = true;
                                 if (!$silent) {
                                     $this->parent->errorControl->raise(200 + $upOk, $upOk, $this->name, $name);
                                 }
                                 # must remove inserted data!
                                 $this->parent->dbo->simpleQuery("DELETE FROM " . $this->dbname . " WHERE " . $wS, $this->parent->debugmode);
                                 $this->deleteUploads($kA);
                                 return false;
                             } else {
                                 if ($upOk != 4 && $upOk != 0) {
                                     // 4 = nothing sent, 0 = sent and ok
                                     # not mandatory but failed, warn about it but do not abort
                                     if (!$silent) {
                                         $this->parent->errorControl->raise(200 + $upOk, $upOk, $this->name, $name);
                                     }
                                     $this->deleteUploads($kA, $name);
                                     // delete possible partial thumbnail process
                                 } else {
                                     if ($upOk == 0) {
                                         $this->parent->dbo->simpleQuery("UPDATE " . $this->dbname . " SET {$name}='y' WHERE {$wS}");
                                     }
                                 }
                             }
                         } else {
                             if ($field[CONS_XML_TIPO] == CONS_TIPO_VC && isset($field[CONS_XML_SPECIAL]) && $field[CONS_XML_SPECIAL] == "urla" && (!isset($data[$name]) || $data[$name] == '')) {
                                 # EMPTY special VC urla might require the data to be fully processed to create the proper result, so we do it after the include
                                 $source = isset($field[CONS_XML_SOURCE]) ? $field[CONS_XML_SOURCE] : "{" . $this->title . "}";
                                 $tp = new CKTemplate($this->parent->template);
                                 $tp->tbreak($source);
                                 $urla = removeSimbols($tp->techo($data), true, false);
                                 if ($urla != '') {
                                     $this->parent->dbo->simpleQuery("UPDATE " . $this->dbname . " SET {$name}=\"{$urla}\" WHERE {$wS}");
                                     $data[$name] = $urla;
                                 }
                                 unset($tp);
                             }
                         }
                     }
                     $this->parent->lastReturnCode = $id;
                     $this->parent->notifyEvent($this, CONS_ACTION_INCLUDE, $data, $startedAt, false);
                     # later notify (there is no early notify for an include)
                     $this->parent->lastReturnCode = $id;
                     // notifyEvent could have changed/consumed lastReturnCode
                     $this->parent->storage['lastactiondata'] =& $data;
                 }
             } else {
                 # null insert? error
                 $this->parent->errorState = true;
                 if (!$silent) {
                     $this->parent->errorControl->raise(142, "", $this->name);
                 }
                 return false;
             }
             if (count($EnumPrunecache) != 0) {
                 $this->autoPrune($EnumPrunecache, $data);
             }
             return true;
             break;
         case CONS_ACTION_DELETE:
             ###################################################### DELETE ############################################
             $wS = "";
             $kA = array();
             $haveallKeys = $this->getKeys($wS, $kA, $data);
             # security
             $Owner = $this->parent->authControl->checkOwner($this, $kA);
             // array with isOwner and isSameGroup
             if ($this->parent->safety && $_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100) {
                 $this->parent->lockPermissions($this, $data, $Owner);
                 if (!$this->parent->authControl->checkPermission($this, CONS_ACTION_DELETE, $Owner, $data)) {
                     $this->parent->errorControl->raise(149, '', $this->name);
                     return false;
                 }
             }
             $this->parent->notifyEvent($this, CONS_ACTION_DELETE, $data, $startedAt, true);
             # early notify
             if ($this->parent->dbo->simpleQuery("DELETE FROM " . $this->dbname . " WHERE " . $wS, $this->parent->debugmode)) {
                 $this->deleteUploads($kA);
                 $this->parent->notifyEvent($this, CONS_ACTION_DELETE, $data, $startedAt, false);
                 # later notify
                 return true;
             } else {
                 $this->parent->errorState = true;
                 if (!$silent) {
                     $this->parent->errorControl->raise(143, "", $this->name);
                 }
                 return false;
             }
             break;
     }
     # switch
 }
예제 #2
0
파일: list.php 프로젝트: Prescia/Prescia
         $laFields[] = $field;
     }
     break;
 case CONS_TIPO_ENUM:
     if (CONS_LIST_AJAXEDITOR && !isset($linkField[CONS_XML_READONLY])) {
         # use ajax editor for enum fields on the list! Keep in mind that the ajax that treats this must be on the page
         $temp = isset($module->fields[$name][CONS_XML_MANDATORY]) ? '' : "<option value=''></option>";
         preg_match("@ENUM \\(([^)]*)\\).*@", $module->fields[$field][CONS_XML_SQL], $regs);
         $xtp = "<option value=\"{enum}\" {\\}" . $field . "|selected|{enum}}>{enum_translated}</option>";
         $tp = new CKTemplate($core->template);
         $tp->tbreak($xtp);
         $enums = explode(",", $regs[1]);
         foreach ($enums as $x) {
             $x = str_replace("'", "", $x);
             $db = array('enum' => $x, 'enum_translated' => $core->langOut($x));
             $temp .= $tp->techo($db);
         }
         unset($tp);
         $field_typed = "<select style='width:99%;margin:0px;border:1px;padding:1px;font-size:9px' onchange=\"listselectchange('" . $module->name . "','{checkkeys}',this.value,'" . $field . "');\">" . $temp . "</select>";
         if ($la == '') {
             $la = '<select style="width:90%;margin:0px;border:1px;padding:1px;font-size:9px" name="la_' . $field . '" id="la_' . $field . '">' . $temp . '</select>';
             $laFields[] = $field;
         }
     } else {
         $field_typed = "{_t}{" . $field . "}{/t}";
     }
     break;
 case CONS_TIPO_UPLOAD:
     $field_typed = "<a href=\"/{" . $field . "_1}\" rel=\"shadowbox[images]\"><img src=\"/{" . $field . "_" . $numThumbs . "}\" width=\"" . $lastThumb[0] . "\" height=\"" . $lastThumb[1] . "\"/></a>";
     $field_title = "";
     $haveListADD = false;
예제 #3
0
파일: module.php 프로젝트: Prescia/Prescia
 function onEcho(&$PAGE)
 {
     if ($this->parent->layout == 2 || $this->parent->servingFile) {
         return;
     }
     # don't mess with ajax
     # Happens just after the template has been parsed (note it received the page as a STRING now), after this, is ECHO and DIE
     ###### -> Construct should add this module to the onEcho array
     if (!$this->devDisable) {
         $thereAreErrors = false;
         if ($this->devCheckHTML || isset($_REQUEST['dev_test'])) {
             if (!function_exists('checkHTML')) {
                 include CONS_PATH_INCLUDE . "checkHTML.php";
             }
             $log = checkHTML($PAGE, false);
             if (count($log) > 0) {
                 $thereAreErrors = true;
                 $this->log[] = implode("<br/>", $log);
                 // for dev_test
             }
             unset($log);
         }
         if (isset($_REQUEST['dev_test'])) {
             if (count($this->parent->log) > 0 || count($this->parent->warning) > 0) {
                 # failed basic test , log it
                 $_SESSION['affbidevut'][2][] = $this->parent->context_str . $this->parent->action . " Reports errors:";
                 foreach ($this->parent->log as $log) {
                     $_SESSION['affbidevut'][2][] = $log;
                 }
                 foreach ($this->parent->warning as $log) {
                     $_SESSION['affbidevut'][2][] = $log;
                 }
             }
             $this->unitTest();
         } else {
             $qs = $this->parent->action . ".html?" . arrayToString(false, array("login", "gfc", "haveinfo", "password", "debugmode", "nosession", "nocache", "dev_html"));
             $totalTime = scriptTime() * 1000;
             // ###############################---
             // ## This is the info strip that stays on top of the site:
             array_unshift($this->log, number_format($totalTime, 2) . "ms (" . CONS_AFF_DATABASECONNECTOR . ": " . number_format($this->parent->dbo->dbt, 2) . "ms, framework: " . number_format($this->overheadTime, 2) . " ms), SQL(s): " . $this->parent->dbo->dbc . ", caches: " . number_format($this->parent->cachetime / 1000) . "ms main, " . number_format($this->parent->cachetimeObj / 1000) . "ms obj" . (isset($this->parent->storage['CORE_CACHECONTROL']) ? " avg: " . number_format($this->parent->storage['CORE_CACHECONTROL'][0] / 1000) . "s factor " . number_format($this->parent->storage['CORE_CACHECONTROL'][1], 2) : "") . " (" . $_SESSION[CONS_SESSION_LANG] . ") (" . ($this->devCheckHTML ? "<a style='color:#" . $this->textColor . "' href='{$qs}&dev_html=0'><strong>checkHTML</strong> is on</a>" : "<a style='color:#" . $this->textColor . "' href='{$qs}&dev_html=1'><strong>checkHTML</strong> is off</a>") . ") (" . ($thereAreErrors ? "<strong><a style='color:#" . $this->textColor . "' href='?dev_log=1'>Errors!</a></strong>" : "no errors") . ") (<a style='color:#" . $this->textColor . "' href='?debugmode=true&nosession=true&nocache=true'>RESET</a>)" . " (<a style='color:#" . $this->textColor . "' href='?dev_help=1'>DEVELOPER OPTIONS</a>) (<a style='color:#" . $this->textColor . "' href=\"" . $qs . "&dev_disable=1\">disable</a>)" . ($this->parent->cacheControl->contentFromCache ? " CACHED CONTENT" : ""));
             // ###############################---
             $pl = strlen($PAGE);
             $tp = new CKTemplate();
             $tp->fetch(CONS_PATH_SYSTEM . "plugins/" . $this->name . "/payload/overlay.html");
             $tp->assign("AFFBIDEV_CONTENT", implode("<br/>", $this->log) . (count($this->parent->warning) != 0 ? "<br/>Warnings:" . implode("<br/>", $this->parent->warning) : ""));
             $arrowColor = $this->parent->cacheControl->contentFromCache ? "#000099" : ($thereAreErrors ? "#BB0000" : "#000000");
             $tp->assign("ARROWCOLOR", $arrowColor);
             $tp->assign("ARROWSIZE", $thereAreErrors ? 20 : 12);
             $PAGE = str_replace("</body>", $tp->techo() . "</body>", $PAGE);
             if (strlen($PAGE) == $pl) {
                 $this->log[] = "WARNING: no /body on page";
                 $PAGE .= $tp->techo();
             }
             $PAGE .= "<!-- bi_dev output logs. To stop this output, disable bi_dev";
             $PAGE .= "\nDbLOG:\n" . implode("\n", $this->parent->dbo->log);
             $C = $_SESSION;
             unset($C['prescia_cache']);
             // the cache can contain whole HTML that would cause havok
             $PAGE .= "\n" . print_r($C, 1) . "\n";
             $PAGE .= "-->";
         }
     }
 }
예제 #4
0
        // fill up title, metas etc
        if (isset($param['title'])) {
            $mytemplate = new CKTemplate($this->template);
            $mytemplate->tbreak($param['title']);
            $this->template->constants['PAGE_TITLE'] = $mytemplate->techo($result);
            $this->storage['LOCKTITLE'] = true;
            unset($mytemplate);
        }
        if (isset($param['metadesc'])) {
            $mytemplate = new CKTemplate($this->template);
            $mytemplate->tbreak($param['metadesc']);
            $this->template->constants['METADESC'] = $mytemplate->techo($result);
            $this->storage['LOCKDESC'] = true;
            unset($mytemplate);
        }
        if (isset($param['metakeys'])) {
            $mytemplate = new CKTemplate($this->template);
            $mytemplate->tbreak($param['metakeys']);
            $this->template->constants['METAKEYS'] = $mytemplate->techo($result);
            $this->storage['LOCKKEYS'] = true;
            unset($mytemplate);
        }
        return true;
    } else {
        unset($this->storage['friendlyurldata']);
        // just in case
        unset($this->storage['friendlyurlmodule']);
        // jic
    }
}
return false;
예제 #5
0
파일: core.php 프로젝트: Prescia/Prescia
 function showTemplate()
 {
     if (count($this->log) > 0) {
         $output = "";
         foreach ($this->log as $saida) {
             $output .= $saida . "\n<br/>";
         }
         $file = $this->debugFile;
         if ($this->debugFile == '' || !is_file($file)) {
             if (is_file(CONS_PATH_PAGES . $_SESSION['CODE'] . "/template/_debugarea.html")) {
                 $file = CONS_PATH_PAGES . $_SESSION['CODE'] . "/template/_debugarea.html";
             } else {
                 $file = CONS_PATH_SETTINGS . "defaults/_debugarea.html";
             }
         }
         $tp = new CKTemplate($this->template);
         $tp->fetch($file);
         $tp->assign("CORE_DEBUG", $output);
         $tp->assign("CORE_DEBUGWARNING", $this->loglevel);
         // CONS_LOGGING_...
         $this->template->constants['CORE_DEBUG'] = $tp->techo();
         unset($tp);
     }
     if (!is_object($this->template) || get_class($this->template) != "CKTemplate") {
         return;
         // huh, no template? oh well
     }
     # Echo dimconfig if something should be outputed
     $data = $this->cacheControl->getCachedContent('dimconfig_auto');
     if ($data === false) {
         $data = $this->dimconfig;
         $dimconfigMD = unserialize(cReadFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/_dimconfig.dat"));
         foreach ($data as $name => $content) {
             if (isset($dimconfigMD[$name])) {
                 if ($dimconfigMD[$name][CONS_XML_TIPO] == CONS_TIPO_UPLOAD) {
                     $FirstfileName = CONS_FMANAGER . $dimconfigMD[$name]['location'];
                     $path = explode("/", $FirstfileName);
                     $fileName = array_pop($path);
                     $path = implode("/", $path) . "/";
                     $hasFile = locateAnyFile($FirstfileName, $ext);
                     if (isset($dimconfigMD[$name][CONS_XML_THUMBNAILS])) {
                         // images
                         $imgs = count($dimconfigMD[$name][CONS_XML_THUMBNAILS]);
                         for ($c = 1; $c <= $imgs; $c++) {
                             $fnamedata = $name . "_" . $c;
                             $data[$fnamedata] = $FirstfileName;
                             $data[$fnamedata . "w"] = "";
                             $data[$fnamedata . "h"] = "";
                             $data[$fnamedata . "t"] = "";
                             $data[$fnamedata . "tr"] = "";
                             $data[$fnamedata . "s"] = "";
                             if ($hasFile) {
                                 $data[$fnamedata] = $FirstfileName;
                                 $popped = explode("/", $FirstfileName);
                                 $data[$fnamedata . "filename"] = array_pop($popped);
                                 if (in_array(strtolower($ext), array("jpg", "gif", "png", "jpeg", "swf"))) {
                                     // image/flash
                                     $h = getimagesize($FirstfileName);
                                     $data[$fnamedata . "w"] = $h[0];
                                     $data[$fnamedata . "h"] = $h[1];
                                     $data[$fnamedata . "s"] = humanSize(filesize($FirstfileName));
                                     if (in_array(strtolower($ext), array("jpg", "gif", "png", "jpeg"))) {
                                         $data[$fnamedata . "t"] = "<img src=\"" . $FirstfileName . "\" width='" . $h[0] . "' height='" . $h[1] . "' alt='' />";
                                         $data[$fnamedata . "tr"] = "<img src=\"" . $FirstfileName . "\" width='100%' height='100%' alt='' />";
                                     } else {
                                         if (strtolower($ext) == "swf") {
                                             $data[$fnamedata . "t"] = str_replace("{FILE}", $FirstfileName, str_replace("{H}", $h[1], str_replace("{W}", $h[0], SWF_OBJECT)));
                                             $data[$fnamedata . "tr"] = $data[$fnamedata . "t"];
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($hasFile) {
                             $fnamedata = $name . "_1";
                             $data[$fnamedata] = $FirstfileName;
                             $data[$fnamedata . "s"] = humanSize(filesize($FirstfileName));
                             $popped = explode("/", $FirstfileName);
                             $data[$fnamedata . "filename"] = array_pop($popped);
                         } else {
                             $fnamedata = $name . "_1";
                             $data[$fnamedata] = "";
                             $data[$fnamedata . "t"] = "";
                             $data[$fnamedata . "tr"] = "";
                             $data[$fnamedata . "s"] = "";
                         }
                     }
                     $this->template->fill($data);
                 } else {
                     $data[$name] = $content;
                 }
             } else {
                 $data[$name] = $content;
             }
         }
         $this->cacheControl->addCachedContent('dimconfig_auto', $data, true);
     }
     $this->template->fill($data);
     $this->template->constants['CHARSET'] = $this->charset;
     if ($this->doctype == "html" || CONS_BROWSER == "IE" && CONS_BROWSER_VERSION < 9) {
         $this->template->assign("_DOCTYPEXML");
     }
     # metadata - fill default values if not set yet (plugins can set)
     if ($this->layout != 2) {
         if ((!isset($this->template->constants['METAKEYS']) || $this->template->constants['METAKEYS'] == '') && $this->dimconfig['metakeys'] != '') {
             $this->template->constants['METAKEYS'] = $this->dimconfig['metakeys'];
         }
         if ((!isset($this->template->constants['METADESC']) || $this->template->constants['METADESC'] == '') && $this->dimconfig['metadesc'] != '') {
             $this->template->constants['METADESC'] = $this->dimconfig['metadesc'];
         }
         // METAS
         if ($this->template->constants['CANONICAL'] == '') {
             $this->template->constants['CANONICAL'] = "http://" . $_SESSION['CANONICAL'] . $this->context_str . $this->action . ".html";
             if (isset($_REQUEST['id'])) {
                 $this->template->constants['CANONICAL'] .= "?id=" . $_REQUEST['id'];
             }
         }
         $metadata = $this->template->constants['METATAGS'];
         if (CONS_PATH_PAGES . $_SESSION['CODE'] . "/template/_meta.xml") {
             $metadata .= cReadFile(CONS_PATH_PAGES . $_SESSION['CODE'] . "/template/_meta.xml");
         }
         $metadata .= "\t<link rel=\"canonical\" href=\"" . $this->template->constants['CANONICAL'] . "\" />\n";
         if ($this->template->constants['METAKEYS'] != '') {
             $metadata .= "\t<meta name=\"keywords\" content=\"" . str_replace("\"", "", $this->template->constants['METAKEYS']) . "\"/>\n";
         }
         if ($this->template->constants['METADESC'] != '') {
             $metadata .= "\t<meta name=\"description\" content=\"" . str_replace("\"", "", $this->template->constants['METADESC']) . "\"/>\n";
             $metadata .= "\t<meta property=\"og:description\" content=\"" . str_replace("\"", "", $this->template->constants['METADESC']) . "\"/>\n";
         }
         $metadata .= "\t<meta property=\"og:type\" content=\"website\" />\n";
         $metadata .= "\t<meta property=\"og:title\" content=\"" . str_replace("\"", "", $this->template->constants['PAGE_TITLE']) . "\" />\n";
         $metadata .= "\t<meta property=\"og:url\" content=\"" . $this->template->constants['CANONICAL'] . "\" />\n";
         if (isset($this->template->constants['METAFIGURE']) && $this->template->constants['METAFIGURE'] != "") {
             if ($this->template->constants['METAFIGURE'][0] != '/') {
                 $this->template->constants['METAFIGURE'] = "/" . $this->template->constants['METAFIGURE'];
             }
             $metadata .= "\t<meta property=\"og:image\" content=\"http://" . $_SESSION['CANONICAL'] . $this->template->constants['METAFIGURE'] . "\" />\n";
             $metadata .= "\t<link rel=\"image_src\" href=\"http://" . $_SESSION['CANONICAL'] . $this->template->constants['METAFIGURE'] . "\" />\n";
         }
         $favfile = CONS_PATH_PAGES . $_SESSION['CODE'] . "/files/favicon";
         if (locateFile($favfile, $ext)) {
             $favfile = CONS_INSTALL_ROOT . $favfile;
             $metadata .= "\t<link rel=\"shortcut icon\" href=\"/favicon." . $ext . "\" />\n";
         } else {
             if (CONS_DEFAULT_FAVICON) {
                 $favfile = "favicon";
                 if (locateFile($favfile, $ext)) {
                     $favfile = CONS_INSTALL_ROOT . $favfile;
                     $metadata .= "\t<link rel=\"shortcut icon\" href=\"/favicon." . $ext . "\" />\n";
                 }
             }
         }
         // Alternate Language and domains versions (only on root index)
         if ($this->context_str == "/" && $this->action == "index") {
             if (CONS_USE_I18N) {
                 $langs = explode(",", CONS_POSSIBLE_LANGS);
                 foreach ($langs as $lang) {
                     if ($lang != $_SESSION[CONS_SESSION_LANG]) {
                         if (count($this->languageTL) > 0) {
                             foreach ($this->languageTL as $fl => $ln) {
                                 if ($ln == $lang) {
                                     $metadata .= "\t<link rel=\"alternate\" hreflang=\"{$lang}\" href=\"/{$fl}/index.html\"/>\n";
                                     break;
                                 }
                             }
                         } else {
                             $metadata .= "\t<link rel=\"alternate\" hreflang=\"{$lang}\" href=\"" . $this->template->constants['CANONICAL'] . "?lang={$lang}\"/>\n";
                         }
                     }
                 }
             }
             foreach ($this->parseRewrite as $domain => $settings) {
                 if ($domain != $this->domain) {
                     $metadata .= "\t<link rel=\"alternate\" hreflang=\"" . ($settings[0] == '' ? CONS_DEFAULT_LANG : $settings[0]) . "\" href=\"http://" . $domain . "\"/>\n";
                 }
             }
         }
         $this->template->constants['METATAGS'] = $metadata;
     }
     $this->removeAutoTags($this->template);
     // print version
     if ($this->template->get("printver") == '') {
         $printVersion = arrayToString($_GET, array("layout"));
         $printVersion .= "&layout=1";
         $this->template->assign("printver", $this->action . ".html?" . $printVersion);
     }
     return $this->template->techo();
 }
예제 #6
0
function echoCalendar(&$containerTP, $width = 0, $month = 0, $year = 0, $highlights = array(), $dayborder = 0, $prevquery = "", $nextquery = "", $divname = "inlinecalendar")
{
    /*
      width should be divisible by 7
      highlights is an array, each with the following:
     	'day' => # day
     	'title' => title on the cell (if nothing, will use the day #)
     	'link' => link if click on the cell (if nothing, no link)
     	'class' => (optional) class for the cell
      dayborder is the number in pixels of border (+margin +padding) you will use on each cell
    */
    $tp = new CKTemplate($containerTP);
    if (!is_file(CONS_PATH_SETTINGS . "defaults/calendar.html")) {
        return "echoCalendar: File not found";
    }
    $tp->fetch(CONS_PATH_SETTINGS . "defaults/calendar.html");
    if ($month == 0) {
        $month = date("m");
    }
    if ($year == 0) {
        $year = date("Y");
    }
    $width = 7 * floor($width / 7);
    $widthDay = floor($width / 7) - 2 * $dayborder;
    $month = (int) $month;
    $year = (int) $year;
    if ($year < 100) {
        $year += 2000;
    }
    if ($month < 10) {
        $month = "0" . $month;
    }
    $initDay = $year . "-" . $month . "-01";
    $endDate = datecalc($initDay, 0, 1);
    $monthLine = $tp->get("_line");
    $dayTp = $tp->get("_day");
    $temp = "";
    // <-- main
    $tempL = "";
    // <-- a line
    $column = date("w", tomktime($initDay));
    // where this month starts
    $today = date("Y-m-d");
    $daysOnPreviousMonth = $column;
    while ($daysOnPreviousMonth > 0) {
        $tempL .= $dayTp->techo(array('class' => 'calendarDayEmpty', "title" => "&nbsp;", "widthday" => $widthDay));
        $daysOnPreviousMonth--;
    }
    while (datecompare($endDate, $initDay)) {
        // while we are within the month (loop will increase initDay)
        $isWeekend = $column == 0 || $column == 6;
        $isToday = $initDay == $today;
        $day = substr($initDay, 8, 2);
        // the following line will put the appropriate class on the day depending on start/end of the project, weekend or deadline
        $output = array("class" => $isToday ? "calendarDayToday" : ($isWeekend ? "calendarDayWeekend" : "calendarDayNormal"), "title" => (int) $day, "widthday" => $widthDay);
        // now we check if we have a highlight
        foreach ($highlights as $high) {
            if ($high['day'] == $day) {
                $output['class'] = isset($high['class']) && $high['class'] != '' ? $high['class'] : "calendarDayHighlight";
                $output['title'] = isset($high['title']) ? $high['title'] : (int) $day;
                if (isset($high['link']) && $high['link'] != '') {
                    $output['title'] = "<a href=\"" . $high['link'] . "\">" . $output['title'] . "</a>";
                }
            }
        }
        $tempL .= $dayTp->techo($output);
        if ($column == 6) {
            // end of a line
            $temp .= $monthLine->techo(array("_day" => $tempL));
            // <-- echo line
            $tempL = "";
        }
        $column++;
        if ($column >= 7) {
            $column = 0;
        }
        $initDay = datecalc($initDay, 0, 0, 1);
    }
    if ($column != 0) {
        // we might not have finished the last line ... check it:
        for ($column = $column; $column < 7; $column++) {
            $tempL .= $dayTp->techo(array('class' => 'calendarDayEmpty', "title" => "", "widthday" => $widthDay));
        }
        $temp .= $monthLine->techo(array("_day" => $tempL));
        // <-- echo line
        $tempL = "";
    }
    $tp->assign("width", $width);
    $tp->assign("month", $month);
    $tp->assign("year", $year);
    $tp->assign("widthday", $widthDay);
    $tp->assign("_line", $temp);
    $tp->assign("calendar", $divname);
    if ($prevquery != '' && $nextquery != '') {
        $tp->assign("ajaxcommandprev", $prevquery);
        $tp->assign("ajaxcommandnext", $nextquery);
    } else {
        $tp->assign("_prevnext");
    }
    return $tp->techo();
}
예제 #7
0
foreach ($theKeys as $ids) {
    if ($ids != "" && preg_match('/' . $ereg_pattern . '/', $ids, $regs)) {
        // valid multiple keys (checkboxes)
        $sql = $basesql;
        for ($pos = 0; $pos < $keyscount; $pos++) {
            // build WHERE based on keys
            $sql['WHERE'][] = $module->name . "." . $keys[$pos] . "=\"" . $regs[$pos + 1] . "\"";
        }
        if ($core->dbo->query($sql, $r, $n) && $n > 0) {
            // get data
            $data = $core->dbo->fetch_assoc($r);
            $data['width'] = $lData['sw'];
            $data['height'] = $lData['sh'];
            $data['left'] = $lData['pfl'] + ($lData['sw'] + $lData['ol']) * ($col - 1);
            $data['top'] = $lData['pft'] + ($lData['sh'] + $lData['ot']) * ($line - 1);
            $aLabel->assign("content", $content->techo($data));
            $pageOutput .= $aLabel->techo($data);
            $col++;
            if ($col > $lData['cols']) {
                $line++;
                $col = 1;
                if ($line > $lData['rows']) {
                    // end page, print it
                    $output .= $aPage->techo(array("_etiqueta" => $pageOutput));
                    $pageOutput = "";
                    $line = 1;
                }
            }
        }
    }
}
예제 #8
0
파일: rss.php 프로젝트: Prescia/Prescia
        continue;
    }
    $sql = $module->get_base_sql('', '', $itemsPerModule);
    $hasCategory = $hasCategory || isset($category[$rssId]) && $category[$rssId] != "";
    $this->dbo->query($sql, $r, $n);
    $dateField = "";
    foreach ($module->fields as $fname => &$field) {
        if ($field[CONS_XML_TIPO] == CONS_TIPO_DATETIME && isset($field[CONS_XML_TIMESTAMP])) {
            $dateField = $fname;
        }
    }
    $ppage = new CKTemplate($this->template);
    $ppage->tbreak($ilt[$rssId]);
    for ($c = 0; $c < $n; $c++) {
        $dados = $this->dbo->fetch_assoc($r);
        $rssItem = array("title" => $dados[$it[$rssId]], "description" => $dados[$idesc[$rssId]], "date" => $dateField != "" ? gmdate("D, d M Y H:i:s", tomktime($dados[$dateField])) . " GMT" : $NOWdate, "link" => $ppage->techo($dados));
        if (!isset($category[$rssId]) || $category[$rssId] != "") {
            if ($hasCategory) {
                $rssItem['category'] = $dados[$category[$rssId]];
            }
        }
        $mylist[] = $rssItem;
    }
    $rssId++;
}
function datesort($a, $b)
{
    return datecompare($a['date'], $b['date']) ? 1 : -1;
}
uksort($mylist, "datesort");
$obj = $rssTemplate->get("_itens");
예제 #9
0
} else {
    if ($file == "") {
        $mail->tbreak("{CONTENT} ");
        # no template nor file
        if (is_file(CONS_PATH_SETTINGS . "defaults/automail.html")) {
            $smh = new CKTemplate($this->template);
            $smh->fetch(CONS_PATH_SETTINGS . "defaults/automail.html");
            $objField = $smh->get("_field");
            $temp = "";
            foreach ($_POST as $name => $data) {
                if ($name != "haveinfo") {
                    $temp .= $objField->techo(array('name' => $name, 'content' => nl2br($data)));
                }
            }
            $smh->assign("_field", $temp);
            $template = $smh->techo();
            unset($smh);
            unset($objField);
        } else {
            foreach ($_POST as $name => $data) {
                if ($name != "haveinfo") {
                    if (strpos($data, "\n") !== false) {
                        $template .= "<strong>{$name}</strong>: <br/><blockquote>" . nl2br($data) . "</blockquote>\n";
                    } else {
                        $template .= "<strong>{$name}</strong>: " . $data . "<br/>\n";
                    }
                }
            }
        }
        $template .= "<br/>\n<br/>" . $this->langOut('sendmail_sent_from') . " : " . $this->domain . $this->context_str . $this->action . "<br/>\n";
        $mail->assign("CONTENT", $template);
예제 #10
0
    $sql = $module->get_base_sql($where, $order, $limit);
    $this->dbo->query($sql, $r, $n);
    $dateField = isset($mod['date']) ? $mod['date'] : '';
    if ($dateField == '') {
        foreach ($module->fields as $fname => &$field) {
            if (($field[CONS_XML_TIPO] == CONS_TIPO_DATETIME || $field[CONS_XML_TIPO] == CONS_TIPO_DATE) && isset($field[CONS_XML_TIMESTAMP])) {
                $dateField = $fname;
            }
        }
    }
    if ($link != '') {
        $ppage = new CKTemplate($this->template);
        $ppage->tbreak($link);
    }
    for ($c = 0; $c < $n; $c++) {
        $dados = $this->dbo->fetch_assoc($r);
        $resultData = array("module" => $mod['module'], "title" => $dados[$title], "description" => $dados[$desc], "date" => $dateField != "" ? $dados[$dateField] : date("Y-m-d H:i:s"), "link" => $link != '' ? $ppage->techo($dados) : '', "id" => $dados[$module->keys[0]]);
        // TODO: does not support multiple keys
        $mylist[] = $resultData;
    }
    $c++;
}
if (!$groupPerModule) {
    function datesort($a, $b)
    {
        return datecompare($a['date'], $b['date']) ? 1 : -1;
    }
    uksort($mylist, "datesort");
}
return $mylist;
// returns: module, title, description, date, link, id
예제 #11
0
파일: module.php 프로젝트: Prescia/Prescia
 function field_interface($field, $action, &$data)
 {
     if ($field == "permissions") {
         $output = "";
         $this->parent->loadPermissions();
         // makes sure it's loaded
         $perm = array();
         $allperm = $this->parent->permissionTemplate;
         // get default permission array
         if (isset($data['permissions']) && $data['permissions'] != "") {
             $perm = unserialize($data['permissions']);
         }
         // loads
         // merge with standard permissions to make sure we have ALL permissions (example: a new module was added and this group still don't have permissions set?)
         foreach ($perm as $name => $permission) {
             $allperm[$name] = $permission;
         }
         // if a permission is lacking, will not override, thus using default
         // load template
         $mytp = new CKTemplate($this->parent->template);
         $mytp->fetch(CONS_PATH_SYSTEM . "plugins/" . $this->name . "/payload/permission_field.html");
         $customPerm = $mytp->get("_custompermission");
         $objPerm = $mytp->get("_permission");
         foreach ($this->parent->modules as $name => $pmodule) {
             if ($pmodule->options[CONS_MODULE_SYSTEM]) {
                 continue;
             }
             // cannot edit system modules
             $locker = "ccccccccc";
             if ($pmodule->permissionOverride != "") {
                 $locker = $pmodule->permissionOverride;
                 $hasSOME = false;
                 for ($pos = 0; $pos < 9; $pos++) {
                     if ($pmodule->permissionOverride[$pos] == "c") {
                         $hasSOME = true;
                         break;
                     }
                 }
             }
             if ($hasSOME) {
                 $thisPermission = array('title' => $this->parent->langOut($name) . (defined("CONS_MODULE_PARTOF") && $pmodule->options[CONS_MODULE_PARTOF] != '' ? " (" . $this->parent->langOut($pmodule->options[CONS_MODULE_PARTOF]) . ")" : ""), 'module' => $name, 'mr_checked' => $allperm[$name][0] == "1" || $locker[0] == "a" ? true : "", 'mr_disabled' => $locker[0] != "c" ? "disabled" : "", 'mw_checked' => $allperm[$name][1] == "1" || $locker[1] == "a" ? true : "", 'mw_disabled' => $locker[1] != "c" ? "disabled" : "", 'me_checked' => $allperm[$name][2] == "1" || $locker[2] == "a" ? true : "", 'me_disabled' => $locker[2] != "c" ? "disabled" : "", 'gr_checked' => $allperm[$name][3] == "1" || $locker[3] == "a" ? true : "", 'gr_disabled' => $locker[3] != "c" ? "disabled" : "", 'gw_checked' => $allperm[$name][4] == "1" || $locker[4] == "a" ? true : "", 'gw_disabled' => $locker[4] != "c" ? "disabled" : "", 'ge_checked' => $allperm[$name][5] == "1" || $locker[5] == "a" ? true : "", 'ge_disabled' => $locker[5] != "c" ? "disabled" : "", 'or_checked' => $allperm[$name][6] == "1" || $locker[6] == "a" ? true : "", 'or_disabled' => $locker[6] != "c" ? "disabled" : "", 'ow_checked' => $allperm[$name][7] == "1" || $locker[7] == "a" ? true : "", 'ow_disabled' => $locker[7] != "c" ? "disabled" : "", 'oe_checked' => $allperm[$name][8] == "1" || $locker[8] == "a" ? true : "", 'oe_disabled' => $locker[8] != "c" ? "disabled" : "");
                 $output .= $objPerm->techo($thisPermission);
             }
             $pos = 9;
         }
         foreach ($this->parent->loadedPlugins as $pname => $plugin) {
             // stand alone plugins (no module)
             if (count($plugin->customPermissions) != 0) {
                 $pos = 9;
                 foreach ($plugin->customPermissions as $ptag => $pi18n) {
                     $thisPermission = array('title' => $pos == 9 ? $this->parent->langOut($pname) : '', 'pname' => 'c_' . $pname . "_" . $ptag, 'ptitle' => $pi18n, 'checked' => isset($allperm["plugin_" . $pname][$pos]) && $allperm["plugin_" . $pname][$pos] == '1' ? true : '');
                     $output .= $customPerm->techo($thisPermission);
                     $pos++;
                 }
             }
         }
         $mytp->assign("_permission", $output);
         $mytp->assign("_custompermission", "");
         $output = $mytp->techo();
         if ($output == '') {
             return false;
         }
         return $output;
     }
     return true;
 }
예제 #12
0
파일: edit.php 프로젝트: Prescia/Prescia
function fillField(&$core, &$module, $name, &$field, &$data, &$p, $isSerialized = false, $basename = "")
{
    $content = "";
    // load l10n for datetimes
    if (!$p['isADD'] && $field[CONS_XML_TIPO] == CONS_TIPO_DATE && isset($data[$name])) {
        $data[$name] = fd($data[$name], $core->intlControl->getDate());
    } else {
        if (!$p['isADD'] && $field[CONS_XML_TIPO] == CONS_TIPO_DATETIME && isset($data[$name])) {
            $data[$name] = fd($data[$name], "H:i:s " . $core->intlControl->getDate());
        }
    }
    // format in language mode
    // pre-fill option arrays
    if (!$p['isADD'] && $field[CONS_XML_TIPO] == CONS_TIPO_OPTIONS && isset($data[$name])) {
        if (isset($data[$name])) {
            $l = strlen($data[$name]);
            for ($c = 0; $c < $l; $c++) {
                $data[$name . $c] = isset($data[$name . $c]) || $data[$name][$c] == "1";
            }
            unset($l);
        }
    }
    // If we are adding, check default values
    if ($p['isADD']) {
        if (strpos($field[CONS_XML_SQL], "AUTO_INCREMENT") !== false) {
            return;
        }
        // do not put autoincrement keys on add
        if (isset($field[CONS_XML_DEFAULT]) && !isset($data[$name])) {
            if ($field[CONS_XML_TIPO] == CONS_TIPO_LINK && $field[CONS_XML_DEFAULT] == "%UID%" && defined("CONS_AUTH_USERMODULE") && $field[CONS_XML_MODULE] == CONS_AUTH_USERMODULE && $_SESSION[CONS_SESSION_ACCESS_LEVEL] > 0 && isset($_SESSION[CONS_SESSION_ACCESS_USER]['id'])) {
                $data[$name] = $_SESSION[CONS_SESSION_ACCESS_USER]['id'];
            } else {
                if ($field[CONS_XML_TIPO] == CONS_TIPO_DATE) {
                    $data[$name] = fd($field[CONS_XML_DEFAULT], $core->intlControl->getDate());
                } else {
                    $data[$name] = $field[CONS_XML_DEFAULT];
                }
            }
        } else {
            if (isset($field[CONS_XML_TIMESTAMP]) || isset($field[CONS_XML_UPDATESTAMP])) {
                if ($field[CONS_XML_TIPO] == CONS_TIPO_DATE) {
                    $data[$name] = date($core->intlControl->getDate());
                } else {
                    $data[$name] = date("H:i:s " . $core->intlControl->getDate());
                }
            }
        }
    } else {
        if (isset($field[CONS_XML_UPDATESTAMP])) {
            if ($field[CONS_XML_TIPO] == CONS_TIPO_DATE) {
                $data[$name] = date($core->intlControl->getDate());
            } else {
                $data[$name] = date("H:i:s " . $core->intlControl->getDate());
            }
        }
    }
    // ajax exceptions?
    if ($core->layout == 2 && $field[CONS_XML_TIPO] == CONS_TIPO_UPLOAD) {
        // ajax mode does not accept uploads
        return;
    }
    // have permission to see this field?
    if ($_SESSION[CONS_SESSION_ACCESS_LEVEL] < 100 && isset($field[CONS_XML_RESTRICT]) && $field[CONS_XML_RESTRICT] > $_SESSION[CONS_SESSION_ACCESS_LEVEL]) {
        return;
    } else {
        // Does this field have a different interface handler? if so use it and continue to the next
        if (in_array($name, $p['cacheCustomFields'])) {
            // detect which plugin has the customHandler and use it. Use the first and leave, if there is more than one, ignore the conflict
            foreach ($module->plugins as $scriptname) {
                // if we didn't have the cache, this would run always, see?
                if (in_array($name, $core->loadedPlugins[$scriptname]->customFields)) {
                    // ok, handle it (if it returns TRUE, ignore this handler)
                    $content = $core->loadedPlugins[$scriptname]->field_interface($name, $p['isADD'], $data);
                    if ($content === false) {
                        return;
                    } else {
                        if ($content !== true) {
                            break;
                            // we will break this foreach plugin search, but continue normally the rest
                        }
                    }
                    $content = "";
                    // if we didn't continue (use the field or ignore), proceed as if this field was normal, thus erase the custom content
                }
            }
        }
        // This field is read-only?
        if (in_array($name, $p['hideKeys']) || isset($field[CONS_XML_READONLY])) {
            if ($p['isADD']) {
                return;
            } else {
                if (!$p['isMultiple']) {
                    $content = isset($data[$name]) ? $data[$name] : ' ';
                } else {
                    return;
                }
            }
        }
        $fillDT = array('field' => $name, 'isADD' => $p['isADD'] ? "true" : "false", 'affreferer' => $module->name, 'affrefererkeys' => implode("_", $p['refererKeys']), 'width' => '99%', 'helper' => '');
        if ($content == '') {
            // format according to type
            $helper = $core->langOut('helper_' . $module->name . "_" . $name);
            if ($helper != 'helper_' . $module->name . "_" . $name) {
                $fillDT['helper'] = $helper;
            }
            switch ($field[CONS_XML_TIPO]) {
                // for each fields ...
                case CONS_TIPO_UPLOAD:
                    // ############################################### FILE(s)
                    if ($p['isMultiple'] || $p['isMup']) {
                        $content = false;
                        continue;
                        // continue will leave only the switch, since switch is considered a loop (??? WHY PHP, WHY ???)
                    }
                    $field_upload = $core->template->get("_upload_field");
                    $using = clone $field_upload;
                    $emptyme = array();
                    if (!$p['isADD']) {
                        $tobjTemp = $core->template->get("_thumb");
                        $path = CONS_FMANAGER . $module->name . "/";
                        $fileName = $name . "_";
                        foreach ($module->keys as $key) {
                            $fileName .= $data[$key] . "_";
                        }
                        $FirstfileName = $path . $fileName . "1";
                        $hasFile = locateAnyFile($FirstfileName, $ext);
                        if (!$hasFile) {
                            $emptyme[] = "_hasFile";
                            if (isset($module->fields[$name][CONS_XML_THUMBNAILS])) {
                                $p['hasImages'] = true;
                                $fillDT['maxres'] = "max " . str_replace(",", "x", $module->fields[$name][CONS_XML_THUMBNAILS][0]);
                            }
                        } else {
                            $fillDT['filesize'] = humanSize(filesize($FirstfileName));
                            $ext = strtolower($ext);
                            $fillDT['download'] = CONS_INSTALL_ROOT . $FirstfileName . "?r=" . rand(0, 9990);
                            $fillDT['ico'] = filetypeIcon($ext);
                            if (in_array($ext, array("jpg", "gif", "swf", "png", "jpeg"))) {
                                $p['hasImages'] = true;
                                $h = getimagesize($FirstfileName);
                                $fillDT['width'] = $h[0];
                                $fillDT['height'] = $h[1];
                                $fillDT['dim'] = $h[0] . "x" . $h[1];
                                if ($h[0] < $p['maxWidth'] && $h[1] < $p['maxHeight']) {
                                    $emptyme[] = "_downloadable";
                                    if ($ext != "swf") {
                                        $emptyme[] = "_swf";
                                    } else {
                                        $emptyme[] = "_img";
                                    }
                                } else {
                                    $emptyme[] = "_presentable";
                                }
                                if (isset($field[CONS_XML_THUMBNAILS])) {
                                    $thumbVersions = count($field[CONS_XML_THUMBNAILS]);
                                    if ($thumbVersions > 1) {
                                        $tObj = clone $tobjTemp;
                                        $tTemp = "";
                                        for ($tv = 2; $tv <= $thumbVersions; $tv++) {
                                            $thumbFile = $path . "t/" . $fileName . $tv;
                                            locateFile($thumbFile, $ext);
                                            $h = getimagesize($thumbFile);
                                            $tTemp .= $tObj->techo(array('tdownload' => CONS_INSTALL_ROOT . $thumbFile));
                                        }
                                        $using->assign("_thumb", $tTemp);
                                    } else {
                                        $emptyme[] = "_hasThumbs";
                                    }
                                } else {
                                    $emptyme[] = "_hasThumbs";
                                }
                            } else {
                                $emptyme[] = "_isImage";
                                $emptyme[] = "_presentable";
                            }
                        }
                    } else {
                        $emptyme[] = "_hasFile";
                    }
                    if (isset($field[CONS_XML_THUMBNAILS])) {
                        $fillDT['maxres'] = "max " . str_replace(",", "x", $field[CONS_XML_THUMBNAILS][0]);
                    }
                    if (isset($field[CONS_XML_FILETYPES])) {
                        $fillDT['exts'] = "(" . $field[CONS_XML_FILETYPES] . ")";
                    }
                    $fillDT['maxsize'] = isset($field[CONS_XML_FILEMAXSIZE]) ? humanSize($field[CONS_XML_FILEMAXSIZE]) : ini_get('upload_max_filesize');
                    if (isset($field[CONS_XML_FILEMAXSIZE]) && $field[CONS_XML_FILEMAXSIZE] > $p['mfs']) {
                        $p['mfs'] = $field[CONS_XML_FILEMAXSIZE];
                    }
                    $content = $using->techo($fillDT, $emptyme);
                    unset($emptyme);
                    break;
                case CONS_TIPO_LINK:
                    // ############################################### LINK TO ANOTHER MODULE
                    $mod = $core->loaded($field[CONS_XML_MODULE]);
                    if ($mod !== false) {
                        $core->safety = false;
                        // <-- in the select, we should always show every item
                        $fillDT['rmodule'] = $field[CONS_XML_MODULE];
                        if ($mod->options[CONS_MODULE_PARENT]) {
                            $field_sel = $core->template->get("_selecttree_field");
                            $using = clone $field_sel;
                            $sql = $mod->get_base_sql();
                            if (isset($data[$name])) {
                                $sql['SELECT'][] = "if (" . $mod->name . "." . $mod->keys[0] . "='" . $data[$name] . "',1,0) as selected";
                            }
                            $sql['SELECT'][] = $mod->name . "." . $mod->title . " as treetitle";
                            $tree = $mod->getContents("", "treetitle", "", "\\", $sql);
                            $using->getTreeTemplate("_sdirs", "_ssubdirs", $tree);
                        } else {
                            $field_sel = $core->template->get("_select_field");
                            $using = clone $field_sel;
                            // checks if this field is/can be filtered by another, if can, leave empty on ADD
                            $canBeFilteredBy = array();
                            if (isset($field[CONS_XML_FILTEREDBY])) {
                                $canBeFilteredBy = $field[CONS_XML_FILTEREDBY];
                                // already a list of local fields
                                $using->assign('helper', $core->langOut("filtered_by") . ": " . implode(",", $canBeFilteredBy));
                                $havePreqs = true;
                                // either on add or edit, field that filter this could be present ... check them!
                                for ($cbf = 0; $cbf < count($canBeFilteredBy); $cbf++) {
                                    if (!isset($data[$canBeFilteredBy[$cbf]]) || $data[$canBeFilteredBy[$cbf]] == '' || $data[$canBeFilteredBy[$cbf]] == '0') {
                                        $havePreqs = false;
                                        break;
                                    }
                                }
                                if (!$havePreqs) {
                                    // we can't fill it, so display the select_other_field message
                                    $using->assign("_optional", "");
                                    $canBeFilteredBy_translated = array();
                                    for ($cbf = 0; $cbf < count($canBeFilteredBy); $cbf++) {
                                        $canBeFilteredBy_translated[$cbf] = $core->langOut($canBeFilteredBy[$cbf]);
                                    }
                                    $using->assign("_options", "<option value=\"\">" . $core->langOut("select_other_field") . ": " . implode(", ", $canBeFilteredBy_translated) . "</option>");
                                } else {
                                    // we can fill this since all prerequisites are present!
                                    $sql = $mod->get_base_sql();
                                    $sql['SELECT'] = array($mod->name . "." . $mod->keys[0] . " as ids", $mod->name . "." . $mod->title . " as title");
                                    if (isset($data[$name])) {
                                        $sql['SELECT'][] = "if (" . $mod->name . "." . $mod->keys[0] . "='" . $data[$name] . "',1,0) as selected";
                                    }
                                    // add filters
                                    foreach ($canBeFilteredBy as $filterfield) {
                                        // we know the data exists because this is an edit, but it could be empty
                                        if ($data[$filterfield] != '') {
                                            $remodeField = $mod->get_key_from($module->fields[$filterfield][CONS_XML_MODULE]);
                                            $sql['WHERE'][] = $mod->name . "." . $remodeField . "=\"" . $data[$filterfield] . "\"";
                                        }
                                    }
                                    if ($core->runContent($mod, $using, $sql, "_options") === false) {
                                        $using->assign("_options");
                                    }
                                }
                                // add the corresponding data for the ajaxContextHandler
                                $p['ajaxContextHandler'][$name] = $canBeFilteredBy;
                            } else {
                                $sql = $mod->get_base_sql();
                                # TODO: this probably won't work on multiple keys
                                $sql['SELECT'] = array($mod->name . "." . $mod->keys[0] . " as ids", $mod->name . "." . $mod->title . " as title");
                                if (isset($data[$name])) {
                                    $sql['SELECT'][] = "if (" . $mod->name . "." . $mod->keys[0] . "='" . $data[$name] . "',1,0) as selected";
                                }
                                //print_r($sql);
                                //die();
                                if ($core->runContent($mod, $using, $sql, "_options") === false) {
                                    $using->assign("_options");
                                }
                            }
                        }
                        $content = $using->techo($fillDT);
                        $core->safety = true;
                        // back to normal mode
                        unset($using);
                    }
                    break;
                case CONS_TIPO_TEXT:
                    // ############################################### TEXT (textarea/cke)
                    $field_txt = $core->template->get("_textarea_field");
                    $using = clone $field_txt;
                    $fillDT['value'] = isset($data[$name]) ? $data[$name] : '';
                    if (isset($field[CONS_XML_HTML])) {
                        $fillDT['value'] = htmlspecialchars($fillDT['value']);
                    }
                    // ckedit will remove entities, so we add an extra layer!
                    $useCKE = isset($field[CONS_XML_HTML]);
                    # CKEdit
                    $content = $using->techo($fillDT);
                    $p['endScript'] .= $useCKE ? "var CKE{$name} = CKEDITOR.replace( '{$name}' , { language : '" . $_SESSION[CONS_SESSION_LANG] . "'" . (isset($module->fields[$name][CONS_XML_SIMPLEEDITFORCE]) ? ",toolbar : 'MiniToolbar'" : "") . "} );\n\tCKFinder.setupCKEditor( CKE{$name}, '/pages/_js/ckfinder/' ) ;\n" : '';
                    # CKEdit + CKFinder
                    unset($using);
                    break;
                case CONS_TIPO_ENUM:
                    // ############################################### LIST OF ITEMS IN ENUM FORM
                    preg_match("@ENUM \\(([^)]*)\\).*@", $field[CONS_XML_SQL], $regs);
                    if ($p['isADD'] && isset($field[CONS_XML_DEFAULT]) && (!isset($data[$name]) || $data[$name] == "")) {
                        $data[$name] = $module->fields[$name][CONS_XML_DEFAULT];
                    }
                    $xtp = "<option value=\"{enum}\" {checked}>{enum_translated}</option>";
                    $tp = new CKTemplate($core->template);
                    $tp->tbreak($xtp);
                    $temp = isset($field[CONS_XML_MANDATORY]) ? '' : "<option value=''></option>";
                    $enums = explode(",", $regs[1]);
                    foreach ($enums as $x) {
                        $x = str_replace("'", "", $x);
                        $db = array('enum' => $x, 'enum_translated' => $core->langOut($x), 'checked' => isset($data[$name]) && $data[$name] == $x ? ' selected="selected"' : '');
                        $temp .= $tp->techo($db);
                    }
                    $content = "<select " . ($p['isMultiple'] ? "onchange=\"\$('me_edit_" . $name . "').checked = true;\"" : "onchange=\"checkConditions();\"") . " id=\"{$name}\" name=\"{$name}\" >" . $temp . "</select>";
                    unset($temp);
                    unset($enums);
                    break;
                case CONS_TIPO_OPTIONS:
                    // ############################################# CHECKBOX LIST
                    $xtp = "<input type=\"checkbox\" onclick=\"checkopts('{field}');\" name=\"{name}\" id=\"{name}\" {checked}/><label for=\"{name}\">{translated}</label><br/>";
                    $tp = new CKTemplate($core->template);
                    $tp->tbreak($xtp);
                    $citem = 0;
                    $temp = "<input type='hidden' name='{$name}' id='{$name}' value=\"" . (isset($data[$name]) ? $data[$name] : "") . "\"/>";
                    foreach ($field[CONS_XML_OPTIONS] as $opt) {
                        $db = array('name' => $name . "_" . $citem, 'field' => $name, 'translated' => $core->langOut(str_replace("'", "", $opt)), 'checked' => isset($data[$name]) && strlen($data[$name]) >= $citem && $data[$name][$citem] == 1 ? ' checked="checked"' : '');
                        $temp .= $tp->techo($db);
                        $citem++;
                    }
                    $content = $temp;
                    unset($temp);
                    break;
                case CONS_TIPO_DATE:
                    // ############################################### DATE / DATETIME
                // ############################################### DATE / DATETIME
                case CONS_TIPO_DATETIME:
                    // updatestamp & includestap already treated befpre switch
                    if ($core->layout != 2) {
                        $fillDT['calendar'] = "<img id='divcalendar_" . $name . "' onclick=\"calendarHandler.showCalendar('" . $name . "','divcalendar_" . $name . "',-80,-8);\" src=\"" . CONS_INSTALL_ROOT . CONS_PATH_PAGES . "_js/calendar/gifs/dyncalendar.gif\" style=\"width:16px;height:16px;position:relative;top:3px;left:2px\" alt=\"" . $core->langOut('calendar') . "\"/>";
                    }
                    $fillDT['width'] = "120px";
                    $p['hasCalendar'] = true;
                case CONS_TIPO_VC:
                    // ############################################### SIMPLE INPUT WITH HEAVY TYPESETTING
                // ############################################### SIMPLE INPUT WITH HEAVY TYPESETTING
                case CONS_TIPO_INT:
                case CONS_TIPO_FLOAT:
                    $field_sel = $core->template->get("_normal_field");
                    $using = clone $field_sel;
                    $fillDT['value'] = isset($data[$name]) ? $data[$name] : '';
                    $fillDT['type'] = "text";
                    if (isset($field[CONS_XML_META])) {
                        if ($field[CONS_XML_META] == "masked") {
                            $fillDT['type'] = "password";
                        }
                        if ($field[CONS_XML_META] == "password") {
                            $fillDT['type'] = "password";
                            if ($_SESSION[CONS_SESSION_ACCESS_LEVEL] != 100) {
                                $data[$name] = "";
                                $fillDT['value'] = "";
                            }
                        }
                    }
                    if ($field[CONS_XML_TIPO] == CONS_TIPO_INT) {
                        if ($fillDT['helper'] == '') {
                            $fillDT['helper'] = $core->langOut('helper_integer');
                        }
                        $p['validators']['integer'][] = "'{$name}'";
                    } else {
                        if ($field[CONS_XML_TIPO] == CONS_TIPO_FLOAT) {
                            if ($fillDT['helper'] == '') {
                                $fillDT['helper'] = $core->langOut('helper_float');
                            }
                            $p['validators']['float'][] = "'{$name}'";
                        } else {
                            if ($field[CONS_XML_TIPO] == CONS_TIPO_DATE) {
                                $p['validators']['date'][] = "'{$name}'";
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = '(' . $core->intlControl->getDate() . ')';
                                }
                            } else {
                                if ($field[CONS_XML_TIPO] == CONS_TIPO_DATETIME) {
                                    if ($fillDT['helper'] == '') {
                                        $fillDT['helper'] = $core->langOut('helper_time') . ' ' . $core->intlControl->getDate() . ')';
                                    }
                                    $p['validators']['datetime'][] = "'{$name}'";
                                }
                            }
                        }
                    }
                    if (isset($field[CONS_XML_SPECIAL])) {
                        switch ($field[CONS_XML_SPECIAL]) {
                            case 'login':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_login');
                                }
                                $p['validators']['login'][] = "'{$name}'";
                                break;
                            case 'mail':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = '(ex: login@servidor.com)';
                                }
                                $p['validators']['mail'][] = "'{$name}'";
                                break;
                            case 'number':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_integer');
                                }
                                $p['validators']['integer'][] = "'{$name}'";
                                break;
                            case 'float':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_float');
                                }
                                $p['validators']['float'][] = "'{$name}'";
                                break;
                            case 'cpf':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_cpf');
                                }
                                $p['validators']['is_cpf'][] = "'{$name}'";
                                break;
                            case 'cnpj':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_cnpj');
                                }
                                $p['validators']['is_cnpj'][] = "'{$name}'";
                                break;
                            case 'id':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_id');
                                }
                                $p['validators']['is_id'][] = "'{$name}'";
                                break;
                            case 'date':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->intlControl->getDate();
                                }
                                $p['validators']['date'][] = "'{$name}'";
                                break;
                            case 'datetime':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_time') . " " . $core->langOut('helper_followedby') . " " . $core->intlControl->getDate() . ')';
                                }
                                $p['validators']['datetime'][] = "'{$name}'";
                                break;
                                break;
                            case 'onlinevideo':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_video');
                                }
                                break;
                            case 'time':
                                if ($fillDT['helper'] == '') {
                                    $fillDT['helper'] = $core->langOut('helper_time');
                                }
                                $p['validators']['time'][] = "'{$name}'";
                                break;
                            default:
                                if (strlen($field[CONS_XML_SPECIAL]) > 10 && substr($field[CONS_XML_SPECIAL], 0, 6) == "slider") {
                                    if (preg_match("@([0-9]*)\\,([0-9]*)@", $field[CONS_XML_SPECIAL], $ereg)) {
                                        unset($using);
                                        unset($field_sel);
                                        $field_sel = $core->template->get("_slider_field");
                                        $using = clone $field_sel;
                                        $fillDT['minor'] = $ereg[1];
                                        $fillDT['major'] = $ereg[2];
                                        if (!is_numeric($fillDT['value'])) {
                                            $fillDT['value'] = $ereg[1];
                                        }
                                        $p['hasSlider'] = true;
                                        if ($fillDT['helper'] == '') {
                                            $fillDT['helper'] = $ereg[1] . " - " . $ereg[2];
                                        }
                                    }
                                }
                                break;
                        }
                    }
                    $content = $using->techo($fillDT);
                    break;
                case CONS_TIPO_ARRAY:
                    # data is an array
                    $p['hasSerializedArray'] = true;
                    $p['serializedArrays'][] = '"' . $name . '"';
                    $p['endScript'] .= "CScontroler.fillData('{$name}'," . JSON_encode($field[CONS_XML_OPTIONS]) . "," . JSON_encode(isset($data[$name]) ? $data[$name] : '') . ");\n";
                    $field_ser = $core->template->get("_serializearray_field");
                    $using = clone $field_ser;
                    $content = $using->techo($fillDT);
                    unset($using);
                    break;
            }
            # switch
            if (isset($field['conditional']) && strpos($field['conditional'], "=") !== false) {
                $temp = explode("=", $field['conditional']);
                $ltemp = trim(strtolower($temp[0]));
                $negation = strpos($ltemp, "!") !== false;
                if ($negation) {
                    $ltemp = trim(str_replace("!", "", $ltemp));
                }
                $rtemp = str_replace("'", "", trim($temp[1]));
                $p['condHandlers'][] = "\$('tableitem" . $name . "').style.display = \$('{$ltemp}').value " . ($negation ? "!=" : "==") . "'{$rtemp}' ? '' : 'none';";
            }
        }
        # content not blank
    }
    # permission to see?
    if ($content === false) {
        return '';
    }
    // if content is false, ignore alltogether
    // build a template object with this field and print it out
    $using = clone $p['objfield'];
    $outdata = array('field' => $content, 'title' => $isSerialized ? substr($name, strlen($basename) + 1) : $name, 'mandatory' => in_array($name, $module->keys) || isset($field[CONS_XML_MANDATORY]) && $field[CONS_XML_MANDATORY] ? "y" : "n");
    if (!$p['isMultiple'] && (!$p['isMup'] || $name != $module->title) && $outdata['mandatory'] == 'y' && !in_array($name, $p['hideKeys']) && $field[CONS_XML_TIPO] != CONS_TIPO_UPLOAD && !isset($field[CONS_XML_READONLY])) {
        // EXCEPTION: a ignorenedit field CAN be blank during EDIT only
        if (!isset($field[CONS_XML_IGNORENEDIT]) || $p['isADD']) {
            $p['$validators']['mandatory'][] = "'{$name}'";
            $p['$validators']['translation'][] = "'" . $core->langOut($name) . "'";
            $p['$validators']['defaults'][] = isset($field[CONS_XML_DEFAULT]) ? "'" . $field[CONS_XML_DEFAULT] . "'" : "''";
        }
    }
    $p['tempOutput'] .= $using->techo($outdata);
    unset($using);
}