Example #1
0
 /**
  * 新建模板
  * @author yongze
  */
 public function actionCreate($id)
 {
     $dsModel = $this->loadModel((int) $id, 'ds');
     $dbModel = $this->loadModel((int) $dsModel->database_id, 'db');
     $model = new Template('Create');
     $data = array();
     if (isset($_POST['Template'])) {
         if (isset($_POST['Template']['type'])) {
             $_POST['Template']['type'] = (int) $_POST['Template']['type'];
         }
         $model->attributes = $_POST['Template'];
         $model->dataset_id = (int) $dsModel->id;
         $model->dataset_name = $dsModel->name;
         if ($model->save()) {
             $this->addLog('template', $model->id, '添加新模板“' . $model->tpname . '”');
             Yii::app()->user->setFlash("success", "新建 <b>{$model->tpname}</b> 模板成功!");
         } else {
             $errorMsg = '';
             $errorErr = $model->getErrors();
             foreach ($errorErr as $value) {
                 $errorMsg .= "\t" . $value[0];
             }
             $errorMsg = trim($errorMsg, ',');
             Yii::app()->user->setFlash("error", $errorMsg);
         }
         $this->redirect(array('/Template/Index/' . $dsModel->id));
     }
     $data['dbModel'] = $dbModel;
     $data['dsModel'] = $dsModel;
     $data['model'] = $model;
     $data['datasetId'] = $id;
     $this->_getFieldsInfos($data['_txtfiled'], $id);
     $this->render('edit', $data);
 }
Example #2
0
 /**
  * Build and return admin interface
  * 
  * Any module providing an admin interface is required to have this function, which
  * returns a string containing the (x)html of it's admin interface.
  * @return string
  */
 function getAdminInterface()
 {
     $this->addCSS('/modules/Templater/css/templates.css');
     $templates = Template::getAllTemplates();
     if (!isset($_REQUEST['template_id'])) {
         $this->smarty->assign('curtemplate', $templates[0]);
     } else {
         if (isset($_REQUEST['save'])) {
             $t = new Template($_REQUEST['template_id']);
             $t->setData(u($_REQUEST['editor']));
             $t->setTimestamp(date('Y-m-d H:i:s'));
             $t->setId(null);
             $t->save();
             $this->smarty->assign('curtemplate', $t);
             $templates = Template::getAllTemplates();
         } else {
             if (isset($_REQUEST['switch_template'])) {
                 $this->smarty->clear_assign('curtemplate');
                 $this->smarty->assign('curtemplate', new Template($_REQUEST['template']));
             } else {
                 if (isset($_REQUEST['switch_revision'])) {
                     $this->smarty->clear_assign('curtemplate');
                     $this->smarty->assign('curtemplate', new Template($_REQUEST['revision']));
                 } else {
                     $this->smarty->assign('curtemplate', new Template($_REQUEST['template_id']));
                 }
             }
         }
     }
     $this->smarty->assign('templates', $templates);
     return $this->smarty->fetch('admin/templates.tpl');
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $fields = explode(",", $input->getOption('fields'));
     if (wire("templates")->get("{$name}")) {
         $output->writeln("<error>Template '{$name}' already exists!</error>");
         exit(1);
     }
     $fieldgroup = new \Fieldgroup();
     $fieldgroup->name = $name;
     $fieldgroup->add("title");
     if ($input->getOption('fields')) {
         foreach ($fields as $field) {
             $this->checkIfFieldExists($field, $output);
             $fieldgroup->add($field);
         }
     }
     $fieldgroup->save();
     $template = new \Template();
     $template->name = $name;
     $template->fieldgroup = $fieldgroup;
     $template->save();
     if (!$input->getOption('nofile')) {
         $this->createTemplateFile($name);
     }
     $output->writeln("<info>Template '{$name}' created successfully!</info>");
 }
Example #4
0
 public static function parse($raw_template)
 {
     //High-level blocks
     $blocks = preg_split('/\\-\\-\\-(\\w+)\\-\\-\\-/', $raw_template, -1, PREG_SPLIT_DELIM_CAPTURE);
     $trimmed_blocks = array_map('trim', $blocks);
     $tp = new Template();
     $tp->title = $trimmed_blocks[2];
     $blocks = array_slice($trimmed_blocks, 4);
     $section_type = "deliverable";
     $ord = 0;
     $vars = array();
     foreach ($blocks as $block) {
         if ($block == "REQUIREMENTS") {
             $section_type = "requirement";
             continue;
         }
         $bits = preg_split('/(^#|[\\r\\n]+#)\\s/', $block, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($bits as $bit) {
             $ts = new TemplateSection();
             $sec_bits = preg_split('/[\\r\\n]#{2,3}/', $bit);
             $ts->title = trim($sec_bits[0]);
             $ts->section_type = $section_type;
             if (count($sec_bits) < 3) {
                 //no help text
                 $ts->help_text = '';
                 $ts->body = trim($sec_bits[1]);
             } else {
                 $ts->help_text = trim($sec_bits[1]);
                 $ts->body = trim($sec_bits[2]);
             }
             $ts->display_order = $ord;
             preg_match_all('/\\{\\{\\s*([^\\}]*)\\}\\}/', $ts->body, $variables);
             foreach ($variables[1] as $var) {
                 $var_bits = explode("|", $var);
                 $var_name = trim(isset($var_bits[0]) ? $var_bits[0] : $var);
                 //avoid dupes
                 if (!array_key_exists($var_name, $vars)) {
                     $vars[$var_name] = array();
                 }
                 if (count($var_bits) > 1) {
                     $vars[$var_name]['name'] = trim($var_bits[1]);
                 }
                 if (count($var_bits) > 2) {
                     $vars[$var_name]['help_text'] = trim($var_bits[2]);
                 }
             }
             $sections[] = $ts;
             $ord++;
         }
     }
     $tp->variables = $vars;
     $tp->save();
     $tp->template_sections()->save($sections);
     return $tp;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Template();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Template'])) {
         $model->attributes = $_POST['Template'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function upload()
 {
     $input = Input::all();
     $validation = Validator::make($input, Template::$rules);
     if ($validation->passes()) {
         $file = Input::file('image');
         // your file upload input field in the form should be named 'file'
         $css = Input::file('css');
         $destinationPath = app_path() . '/views/uploads/layouts';
         $csspath = public_path() . '/assets/css';
         $thumbdestination = public_path() . '/assets/thumb';
         $name = Input::get('name');
         $newname = str_replace(' ', '_', $name);
         $filename = $file->getClientOriginalName();
         //$extension =$file->getClientOriginalExtension();
         //if you need extension of the file
         $uploadSuccess = Input::file('image')->move($destinationPath, $filename);
         $extension = Input::file('thumbnail')->getClientOriginalExtension();
         $uploadthumbnail = Input::file('thumbnail')->move($thumbdestination, $newname . '.' . $extension);
         $uploadcss = Input::file('css')->move($csspath, $css . '.css');
         $input = Input::all();
         if ($uploadSuccess && $uploadthumbnail) {
             //return Response::json('success', 200); // or do a redirect with some message that file was uploaded
             $this->template->name = Input::get('name');
             $this->template->file = $filename;
             $this->template->css = $css;
             $this->template->save();
             $id = DB::getPdo()->lastInsertId();
             $thumb = new Image_thumbnail();
             $thumb->img = $newname . '.' . $extension;
             $thumb->title = $name;
             $thumb->t_id = $id;
             $thumb->save();
             return Redirect::route('templates.definefields', array('id' => $id));
         }
     }
     return Redirect::route('templates.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }
Example #7
0
 public function save()
 {
     if ($this->html) {
         $body = '{if !$html}' . "\n" . $this->body . "\n" . '{/if}{*html*}' . "\n" . '{if $html}' . "\n" . $this->html . "\n" . '{/if}{*html*}';
     } else {
         $body = $this->body;
     }
     if ($this->isFragment()) {
         $this->code = $body;
     } else {
         $this->code = $this->subject . "\n" . $body;
     }
     return parent::save();
 }
 protected function envTemplate()
 {
     $template = new Template();
     $template->color = '1';
     $template->layout = '1';
     $template->user_id = 1;
     $template->save();
     $template2 = new Template();
     $template2->color = '1';
     $template2->layout = '1';
     $template2->user_id = 2;
     $template2->save();
     $template3 = new Template();
     $template3->color = '1';
     $template3->layout = '1';
     $template3->user_id = 3;
     $template3->save();
 }
Example #9
0
 /**
  * @before _secure, _admin
  */
 public function createNewsletter()
 {
     $this->seo(array("title" => "Create Newsletter", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $groups = \Group::all(array(), array("name", "id"));
     if (count($groups) == 0) {
         $this->_createGroup(array("name" => "All", "users" => json_encode(array("*"))));
         $groups = \Group::all(array(), array("name", "id"));
     }
     if (RequestMethods::post("action") == "createNewsletter") {
         $message = new Template(array("subject" => RequestMethods::post("subject"), "body" => RequestMethods::post("body")));
         $message->save();
         $newsletter = new Newsletter(array("template_id" => $message->id, "group_id" => RequestMethods::post("user_group"), "scheduled" => RequestMethods::post("scheduled")));
         $newsletter->save();
         $view->set("success", TRUE);
     }
     $view->set("groups", $groups);
 }
 /**
  * Create a template
  * Add a fieldgroup with the 'title' field
  * @todo add all global fields instead
  */
 public function update()
 {
     $t = new Template();
     $t->name = $this->getTemplateName();
     $fg = new Fieldgroup();
     $fg->name = $this->getTemplateName();
     foreach ($this->fields as $field) {
         // add global fields
         if (!($field->flags & Field::flagGlobal)) {
             continue;
         }
         $fg->add($field);
     }
     $fg->save();
     $t->fieldgroup = $fg;
     $t->fieldgroup->save();
     $t->save();
     $this->templateSetup($t);
     $t->fieldgroup->save();
     $t->save();
     return $t;
 }
Example #11
0
 /**
  * Add
  */
 public function executeAdd()
 {
     if ($this->isGET()) {
         return $this->renderJson(array("success" => false, "info" => "POST Only."));
     } else {
         $template = new Template();
         $template->setName($this->getRequestParameter('name'));
         $template->setType($this->getRequestParameter('type'));
         $template->save();
         foreach ($this->getRequestParameter('record') as $data) {
             $record = new TemplateRecord();
             $record->setTemplateId($template->getId());
             $record->setName($data['name']);
             $record->setType($data['type']);
             $record->setContent($data['content']);
             $record->setTtl($data['ttl']);
             if ($data['type'] == 'MX') {
                 $record->setPrio($data['prio']);
             }
             $record->save();
         }
         return $this->renderJson(array("success" => true, "info" => "Template added."));
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Template();
     $model->companyId = Yii::app()->user->getState('selectedCompanyId');
     $model->allowFreeTextField = 1;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Template'])) {
         $model->attributes = $_POST['Template'];
         $model->companyId = Yii::app()->user->getState('selectedCompanyId');
         if ($model->save()) {
             if ($this->updateRows($model)) {
                 if (isset($_POST['AddRow']) || isset($_POST['deleterow'])) {
                     $this->redirect(array('update', 'id' => $model->id));
                 } else {
                     $this->redirect(array('admin'));
                 }
             }
         }
     }
     $model->dateChanged = User::getDateFormatted(date('Y-m-d'));
     $this->render('create', array('model' => $model, 'update' => false));
 }
Example #13
0
                }
                // if we got here, we're golden.
            } catch (CmsEditContentException $e) {
                $error .= "<li>" . $e->getMessage() . "</li>";
                $validinfo = false;
            }
        }
        if ($validinfo) {
            $newtemplate = new Template();
            $newtemplate->name = $template;
            $newtemplate->content = $content;
            //$newtemplate->stylesheet = $stylesheet;
            $newtemplate->active = $active;
            $newtemplate->default = 0;
            Events::SendEvent('Core', 'AddTemplatePre', array('template' => &$newtemplate));
            $result = $newtemplate->save();
            if ($result) {
                Events::SendEvent('Core', 'AddTemplatePost', array('template' => &$newtemplate));
                // put mention into the admin log
                audit($newtemplate->id, 'HTML-template: ' . $template, 'Added');
                redirect($from);
                return;
            } else {
                $error .= "<li>" . lang('errorinsertingtemplate') . "{$query}</li>";
            }
        }
    }
}
include_once "header.php";
if (!$access) {
    //echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('addtemplate')))."</p></div>";
Example #14
0
function doPopulateDatabase()
{
    // Check for a config file, if it doesn't exist go through the steps to create it.
    if (!file_exists(dirname(__FILE__) . '/config.php')) {
        header("Location: " . $_SERVER["SCRIPT_NAME"] . "?do=step1");
        return;
    }
    require_once dirname(__FILE__) . "/config.php";
    require_once dirname(__FILE__) . "/fwork/lib/Doctrine/Doctrine.php";
    spl_autoload_register(array("Doctrine", "autoload"));
    Doctrine_Manager::connection($config["database"]["dsn"]);
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_TBLNAME_FORMAT, $config["database"]["prefix"] . "%s");
    Doctrine::createTablesFromModels(dirname(__FILE__) . "/models");
    $time = date("Y-m-d H:i:s");
    // roles
    $role_admin = new Role();
    $role_admin->name = "Admin";
    $role_admin->auth = 0xffffffff;
    $role_admin->created = $time;
    $role_admin->save();
    $role_staff = new Role();
    $role_staff->name = "Staff";
    $role_staff->auth = 0x7c700;
    $role_staff->created = $time;
    $role_staff->save();
    $role_guest = new Role();
    $role_guest->name = "Guest";
    $role_guest->auth = 0x0;
    $role_guest->created = $time;
    $role_guest->save();
    // staff
    $staff = new Staff();
    $staff->nickname = "admin";
    $staff->setPassword("admin");
    $staff->Role = $role_admin;
    $staff->admin = true;
    $staff->comment = "Administrator";
    $staff->created = $time;
    $staff->save();
    // task types
    $tasktypes = array('Raw Cap', 'Translate', 'Time', 'Translation Check', 'Typeset', 'Edit', 'Encode', 'Quality Check', 'Karaoke', 'Miscellaneous', 'Translate Signs', 'Release');
    foreach ($tasktypes as $key => $name) {
        $tasktype = new TaskType();
        $tasktype->name = $name;
        $tasktype->created = $time;
        $tasktype->save();
        $tasktypes[$key] = $tasktype;
    }
    // template
    $template = new Template();
    $template->name = "Default";
    $template->model = $tasktypes[0]->id . ":0->" . $tasktypes[1]->id . ":0; " . $tasktypes[0]->id . ":0->" . $tasktypes[10]->id . ":0; " . $tasktypes[10]->id . ":0->" . $tasktypes[4]->id . ":0; " . $tasktypes[4]->id . ":0->" . $tasktypes[3]->id . ":0; " . $tasktypes[1]->id . ":0->" . $tasktypes[2]->id . ":0; " . $tasktypes[1]->id . ":0->" . $tasktypes[3]->id . ":0; " . $tasktypes[3]->id . ":0->" . $tasktypes[5]->id . ":0; " . $tasktypes[5]->id . ":0->" . $tasktypes[6]->id . ":0; " . $tasktypes[6]->id . ":0->" . $tasktypes[7]->id . ":0; " . $tasktypes[7]->id . ":0->" . $tasktypes[11]->id . ":0; " . $tasktypes[2]->id . ":0->" . $tasktypes[5]->id . ":0; ";
    $template->created = $time;
    $template->save();
    // settings
    $settings = array('site.gzip' => true, 'site.gentime' => true);
    foreach ($settings as $name => $value) {
        $setting = new Setting();
        $setting->name = $name;
        $setting->value = $value;
        $setting->save();
        unset($setting);
    }
    echo <<<EOS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
\t<title>Frac :: Install</title>
\t<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
\t<h2>Frac Installer</h2>
\t<p>Table data populated successfully. You may now proceed to your <a href="./">Frac installation</a>. The username and password are "admin".</p>
</body>
</html>
EOS;
}
 /**
  * @return array Errors  Import Template information
  */
 public static function importTemplates($root, $companyId, &$errors)
 {
     $nodeTemplates = $root->getElementsByTagName('template');
     foreach ($nodeTemplates as $nodeTemplate) {
         if ($root->getAttribute('version') > 1.0) {
             $errors[] = '*TemplateVersion*' . Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version');
             $errors[] = Yii::t('lazy8', 'Select a file and try again');
         }
         $modelTemplate = new Template();
         $modelTemplate->companyId = $companyId;
         $modelTemplate->name = $nodeTemplate->getAttribute('name');
         $modelTemplate->desc = $nodeTemplate->getAttribute('desc');
         $modelTemplate->sortOrder = $nodeTemplate->getAttribute('sortorder');
         $modelTemplate->allowAccountingView = $nodeTemplate->getAttribute('allowaccountingview') == '1' ? 1 : 0;
         $modelTemplate->allowFreeTextField = $nodeTemplate->getAttribute('allowfreetextfield') == '1' ? 1 : 0;
         $modelTemplate->freeTextFieldDefault = $nodeTemplate->getAttribute('freetextfielddefault');
         $modelTemplate->allowFilingTextField = $nodeTemplate->getAttribute('allowfilingtextfield') == '1' ? 1 : 0;
         $modelTemplate->filingTextFieldDefault = $nodeTemplate->getAttribute('filingtextfielddefault');
         $modelTemplate->forceDateToday = $nodeTemplate->getAttribute('forcedatetoday');
         if (!$modelTemplate->save()) {
             $errors[] = Yii::t('lazy8', 'Could not create the modelTemplate, bad paramters') . ';name=' . $modelTemplate->name . ';' . serialize($modelTemplate->getErrors());
             return $errors;
         }
         $nodesTemplateRows = $nodeTemplate->getElementsByTagName('templaterow');
         foreach ($nodesTemplateRows as $nodesTemplateRow) {
             $modelTemplateRow = new TemplateRow();
             $modelTemplateRow->templateId = $modelTemplate->id;
             $modelTemplateRow->name = $nodesTemplateRow->getAttribute('name');
             $modelTemplateRow->desc = $nodesTemplateRow->getAttribute('desc');
             $modelTemplateRow->sortOrder = $nodesTemplateRow->getAttribute('sortorder');
             $modelTemplateRow->isDebit = $nodesTemplateRow->getAttribute('isdebit') == '1' ? 1 : 0;
             $modelTemplateRow->defaultAccountId = Template::FindAccountId($nodesTemplateRow->getAttribute('defaultaccount'), $modelTemplate->companyId);
             $modelTemplateRow->defaultValue = $nodesTemplateRow->getAttribute('defaultvalue');
             $modelTemplateRow->allowMinus = $nodesTemplateRow->getAttribute('allowminus') == '1' ? 1 : 0;
             $modelTemplateRow->phpFieldCalc = $nodesTemplateRow->getAttribute('phpfieldcalc');
             $modelTemplateRow->allowChangeValue = $nodesTemplateRow->getAttribute('allowchangevalue') == '1' ? 1 : 0;
             $modelTemplateRow->allowRepeatThisRow = $nodesTemplateRow->getAttribute('allowrepeatthisrow') == '1' ? 1 : 0;
             $modelTemplateRow->allowCustomer = $nodesTemplateRow->getAttribute('allowcustomer') == '1' ? 1 : 0;
             $modelTemplateRow->allowNotes = $nodesTemplateRow->getAttribute('allownotes') == '1' ? 1 : 0;
             $modelTemplateRow->isFinalBalance = $nodesTemplateRow->getAttribute('isfinalbalance') == '1' ? 1 : 0;
             if (!$modelTemplateRow->save()) {
                 $modelTemplate->delete();
                 $errors[] = Yii::t('lazy8', 'Could not create the TemplateRow, bad paramters') . ';' . serialize($modelTemplateRow->getErrors());
                 return;
             }
             $nodesTemplateRowAccounts = $nodesTemplateRow->getElementsByTagName('templaterowaccount');
             foreach ($nodesTemplateRowAccounts as $nodesTemplateRowAccount) {
                 $modelTemplateRowAccount = new TemplateRowAccount();
                 $modelTemplateRowAccount->templateRowId = $modelTemplateRow->id;
                 $modelTemplateRowAccount->accountId = Template::FindAccountId($nodesTemplateRowAccount->getAttribute('code'), $modelTemplate->companyId);
                 if ($modelTemplateRowAccount->accountId != 0) {
                     if (!$modelTemplateRowAccount->save()) {
                         $modelTemplate->delete();
                         $errors[] = Yii::t('lazy8', 'Could not create the TemplateRowAccount, bad paramters') . ';' . serialize($modelTemplateRowAccount->getErrors());
                         return;
                     }
                 } else {
                     $errors[] = Yii::t('lazy8', 'Could not create the Account, bad account number') . ';' . $nodesTemplateRowAccount->getAttribute('code');
                 }
             }
         }
     }
 }
function parseTemplates($intElmntId, $strCommand)
{
    global $_PATHS, $objLang, $_CONF, $_CLEAN_POST, $objLiveUser;
    $objTpl = new HTML_Template_IT($_PATHS['templates']);
    switch ($strCommand) {
        case CMD_LIST:
            $objTpl->loadTemplatefile("multiview.tpl.htm");
            $objTpl->setVariable("MAINTITLE", $objLang->get("pcmsTemplates", "menu"));
            $objTemplate = Template::selectByPK($intElmntId);
            if (empty($intElmntId)) {
                $strTemplateName = "Website";
            } else {
                if (is_object($objTemplate)) {
                    $strTemplateName = $objTemplate->getName();
                } else {
                    $strTemplateName = "";
                }
            }
            if (is_object($objTemplate)) {
                $objFields = $objTemplate->getFields();
                if (is_object($objFields)) {
                    //*** Initiate field loop.
                    $listCount = 0;
                    $intPosition = request("pos");
                    $intPosition = !empty($intPosition) && is_numeric($intPosition) ? $intPosition : 0;
                    $intPosition = floor($intPosition / $_SESSION["listCount"]) * $_SESSION["listCount"];
                    $objFields->seek($intPosition);
                    //*** Loop through the fields.
                    foreach ($objFields as $objField) {
                        $objFieldType = TemplateFieldType::selectByPK($objField->getTypeId());
                        $strMeta = $objLang->get("editedBy", "label") . " " . $objField->getUsername() . ", " . Date::fromMysql($objLang->get("datefmt"), $objField->getModified());
                        $objTpl->setCurrentBlock("multiview-item");
                        $objTpl->setVariable("BUTTON_DUPLICATE", $objLang->get("duplicate", "button"));
                        $objTpl->setVariable("BUTTON_DUPLICATE_HREF", "javascript:PTemplateField.duplicate({$objField->getId()});");
                        $objTpl->setVariable("BUTTON_REMOVE", $objLang->get("delete", "button"));
                        $objTpl->setVariable("BUTTON_REMOVE_HREF", "javascript:PTemplateField.remove({$objField->getId()});");
                        $objTpl->setVariable("MULTIITEM_VALUE", $objField->getId());
                        $objTpl->setVariable("MULTIITEM_HREF", "href=\"?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$objField->getId()}&amp;cmd=" . CMD_EDIT_FIELD . "\"");
                        $strValue = htmlspecialchars($objField->getName());
                        $strShortValue = getShortValue($strValue, 50);
                        $intSize = strlen($strValue);
                        $objTpl->setVariable("MULTIITEM_NAME", $intSize > 50 ? $strShortValue : $strValue);
                        $objTpl->setVariable("MULTIITEM_TITLE", $intSize > 50 ? $strValue : "");
                        $objTpl->setVariable("MULTIITEM_TYPE", ", " . $objFieldType->getName());
                        $objTpl->setVariable("MULTIITEM_TYPE_CLASS", "field");
                        $objTpl->setVariable("MULTIITEM_META", $strMeta);
                        $objTpl->parseCurrentBlock();
                        $listCount++;
                        if ($listCount >= $_SESSION["listCount"]) {
                            break;
                        }
                    }
                    //*** Render page navigation.
                    $pageCount = ceil($objFields->count() / $_SESSION["listCount"]);
                    if ($pageCount > 0) {
                        $currentPage = ceil(($intPosition + 1) / $_SESSION["listCount"]);
                        $previousPos = $intPosition - $_SESSION["listCount"] > 0 ? $intPosition - $_SESSION["listCount"] : 0;
                        $nextPos = $intPosition + $_SESSION["listCount"] < $objFields->count() ? $intPosition + $_SESSION["listCount"] : $intPosition;
                        $objTpl->setVariable("PAGENAV_PAGE", sprintf($objLang->get("pageNavigation", "label"), $currentPage, $pageCount));
                        $objTpl->setVariable("PAGENAV_PREVIOUS", $objLang->get("previous", "button"));
                        $objTpl->setVariable("PAGENAV_PREVIOUS_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;pos={$previousPos}");
                        $objTpl->setVariable("PAGENAV_NEXT", $objLang->get("next", "button"));
                        $objTpl->setVariable("PAGENAV_NEXT_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;pos={$nextPos}");
                        //*** Top page navigation.
                        for ($intCount = 0; $intCount < $pageCount; $intCount++) {
                            $objTpl->setCurrentBlock("multiview-pagenavitem-top");
                            $position = $intCount * $_SESSION["listCount"];
                            if ($intCount != $intPosition / $_SESSION["listCount"]) {
                                $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;pos={$position}\"");
                            }
                            $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1);
                            $objTpl->parseCurrentBlock();
                        }
                        //*** Top page navigation.
                        for ($intCount = 0; $intCount < $pageCount; $intCount++) {
                            $objTpl->setCurrentBlock("multiview-pagenavitem-bottom");
                            $position = $intCount * $_SESSION["listCount"];
                            if ($intCount != $intPosition / $_SESSION["listCount"]) {
                                $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;pos={$position}\"");
                            }
                            $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1);
                            $objTpl->parseCurrentBlock();
                        }
                    }
                }
            }
            //*** Render list action pulldown.
            $arrActions[$objLang->get("choose", "button")] = 0;
            $arrActions[$objLang->get("delete", "button")] = "delete";
            $arrActions[$objLang->get("duplicate", "button")] = "duplicate";
            foreach ($arrActions as $key => $value) {
                $objTpl->setCurrentBlock("multiview-listactionitem");
                $objTpl->setVariable("LIST_ACTION_TEXT", $key);
                $objTpl->setVariable("LIST_ACTION_VALUE", $value);
                $objTpl->parseCurrentBlock();
            }
            //*** Render the rest of the page.
            $objTpl->setCurrentBlock("multiview");
            $objTpl->setVariable("ACTIONS_OPEN", $objLang->get("pcmsOpenActionsMenu", "menu"));
            $objTpl->setVariable("ACTIONS_CLOSE", $objLang->get("pcmsCloseActionsMenu", "menu"));
            $objTpl->setVariable("LIST_LENGTH_HREF_10", "href=\"?list=10&amp;cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}\"");
            $objTpl->setVariable("LIST_LENGTH_HREF_25", "href=\"?list=25&amp;cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}\"");
            $objTpl->setVariable("LIST_LENGTH_HREF_100", "href=\"?list=100&amp;cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}\"");
            switch ($_SESSION["listCount"]) {
                case 10:
                    $objTpl->setVariable("LIST_LENGTH_HREF_10", "");
                    break;
                case 25:
                    $objTpl->setVariable("LIST_LENGTH_HREF_25", "");
                    break;
                case 100:
                    $objTpl->setVariable("LIST_LENGTH_HREF_100", "");
                    break;
            }
            $objTpl->setVariable("LIST_LENGTH_HREF", "&amp;cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}");
            $objTpl->setVariable("LIST_WITH_SELECTED", $objLang->get("withSelected", "label"));
            $objTpl->setVariable("LIST_ACTION_ONCHANGE", "PTemplateField.multiDo(this, this[this.selectedIndex].value)");
            $objTpl->setVariable("LIST_ITEMS_PER_PAGE", $objLang->get("itemsPerPage", "label"));
            $objTpl->setVariable("BUTTON_LIST_SELECT", $objLang->get("selectAll", "button"));
            $objTpl->setVariable("BUTTON_LIST_SELECT_HREF", "javascript:PTemplateField.multiSelect()");
            $objTpl->setVariable("BUTTON_NEWSUBJECT", $objLang->get("newTemplate", "button"));
            $objTpl->setVariable("BUTTON_NEWSUBJECT_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_ADD);
            $objTpl->setVariable("BUTTON_NEWSTRUCTURE", $objLang->get("newStructure", "button"));
            $objTpl->setVariable("BUTTON_NEWSTRUCTURE_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_ADD_STRUCTURE);
            if (is_object($objTemplate)) {
                $objTpl->setVariable("BUTTON_NEWFIELD", $objLang->get("newField", "button"));
                $objTpl->setVariable("BUTTON_NEWFIELD_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_ADD_FIELD);
                $objTpl->setVariable("BUTTON_EDIT", $objLang->get("edit", "button"));
                $objTpl->setVariable("BUTTON_EDIT_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_EDIT);
                $objTpl->setVariable("BUTTON_REMOVE", $objLang->get("removeTemplate", "button"));
                $objTpl->setVariable("BUTTON_REMOVE_HREF", "javascript:PTemplate.remove({$intElmntId});");
                $objTpl->setVariable("BUTTON_MAIN_DUPLICATE", $objLang->get("duplicateTemplate", "button"));
                $objTpl->setVariable("BUTTON_MAIN_DUPLICATE_HREF", "javascript:PTemplate.duplicate({$intElmntId});");
                $objTpl->setVariable("BUTTON_EXPORT_TEMPLATE", $objLang->get("export", "button"));
                $objTpl->setVariable("BUTTON_EXPORT_TEMPLATE_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_EXPORT_TEMPLATE);
                $objTpl->setVariable("BUTTON_IMPORT_TEMPLATE", $objLang->get("import", "button"));
                $objTpl->setVariable("BUTTON_IMPORT_TEMPLATE_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_IMPORT_TEMPLATE);
            }
            $objTpl->setVariable("LABEL_SUBJECT", $objLang->get("fieldsFor", "label") . " ");
            $objTpl->setVariable("SUBJECT_NAME", $strTemplateName);
            $objTpl->parseCurrentBlock();
            break;
        case CMD_REMOVE:
            $objTemplate = Template::selectByPK($intElmntId);
            $intParent = $objTemplate->getParentId();
            $objTemplate->delete();
            header("Location: " . Request::getURI() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST . "&eid=" . $intParent);
            exit;
            break;
        case CMD_DUPLICATE:
            $objTemplate = Template::selectByPK($intElmntId);
            $intParent = $objTemplate->getParentId();
            $objTemplate->setUsername($objLiveUser->getProperty("name"));
            $objDuplicate = $objTemplate->duplicate($objLang->get("copyOf", "label"));
            //*** Redirect the page.
            $strReturnTo = request('returnTo');
            if (empty($strReturnTo)) {
                header("Location: " . Request::getURI() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST . "&eid=" . $intParent);
                exit;
            } else {
                header("Location: " . Request::getURI() . $strReturnTo);
                exit;
            }
            break;
        case CMD_REMOVE_FIELD:
            if (strpos($intElmntId, ',') !== false) {
                //*** Multiple elements submitted.
                $arrFields = explode(',', $intElmntId);
                $objFields = TemplateField::selectByPK($arrFields);
                $intParent = $objFields->current()->getTemplateId();
                foreach ($objFields as $objField) {
                    $objField->delete();
                }
            } else {
                //*** Single element submitted.
                $objField = TemplateField::selectByPK($intElmntId);
                $intParent = $objField->getTemplateId();
                $objField->delete();
            }
            header("Location: " . Request::getURI() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST . "&eid=" . $intParent);
            exit;
            break;
        case CMD_DUPLICATE_FIELD:
            if (strpos($intElmntId, ',') !== false) {
                //*** Multiple elements submitted.
                $arrFields = explode(',', $intElmntId);
                $objFields = TemplateField::selectByPK($arrFields);
                $intParent = $objFields->current()->getTemplateId();
                foreach ($objFields as $objField) {
                    $objField->setUsername($objLiveUser->getProperty("name"));
                    $objField->duplicate($objLang->get("copyOf", "label"));
                }
            } else {
                //*** Single element submitted.
                $objField = TemplateField::selectByPK($intElmntId);
                $intParent = $objField->getTemplateId();
                $objField->setUsername($objLiveUser->getProperty("name"));
                $objField->duplicate($objLang->get("copyOf", "label"));
            }
            header("Location: " . Request::getURI() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST . "&eid=" . $intParent);
            exit;
            break;
        case CMD_ADD:
        case CMD_EDIT:
            $objTpl->loadTemplatefile("template.tpl.htm");
            //*** Check if the rootfolder has been submitted.
            if ($strCommand == CMD_EDIT && $intElmntId == 0) {
                //*** Redirect to list mode.
                header("Location: " . Request::getURI() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST . "&eid=" . $intElmntId);
                exit;
            }
            //*** Post the template form if submitted.
            if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "addTemplate") {
                //*** The template form has been posted.
                $blnError = false;
                //*** Check sanitized input.
                if (is_null($_CLEAN_POST["frm_ispage"])) {
                    $objTpl->setVariable("ERROR_ISPAGE_ON", " error");
                    $objTpl->setVariable("ERROR_ISPAGE", $objLang->get("isPage", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_iscontainer"])) {
                    $objTpl->setVariable("ERROR_ISCONTAINER_ON", " error");
                    $objTpl->setVariable("ERROR_ISCONTAINER", $objLang->get("isContainer", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_forcecreation"])) {
                    $objTpl->setVariable("ERROR_FORCECREATION_ON", " error");
                    $objTpl->setVariable("ERROR_FORCECREATION", $objLang->get("forceCreation", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_name"])) {
                    $objTpl->setVariable("ERROR_NAME_ON", " error");
                    $objTpl->setVariable("ERROR_NAME", $objLang->get("templateName", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_apiname"])) {
                    $objTpl->setVariable("ERROR_APINAME_ON", " error");
                    $objTpl->setVariable("ERROR_APINAME", $objLang->get("commonTypeWord", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_description"])) {
                    $objTpl->setVariable("ERROR_NOTES_ON", " error");
                    $objTpl->setVariable("ERROR_NOTES", $objLang->get("commonTypeText", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["dispatch"])) {
                    $blnError = true;
                }
                if ($blnError === true) {
                    //*** Display global error.
                    $objTpl->setVariable("FORM_NAME", "templateForm");
                    $objTpl->setVariable("FORM_ISPAGE_VALUE", isset($_POST["frm_ispage"]) && $_POST["frm_ispage"] == "on" ? "checked=\"checked\"" : "");
                    $objTpl->setVariable("FORM_NAME_VALUE", $_POST["frm_name"]);
                    $objTpl->setVariable("FORM_APINAME_VALUE", $_POST["frm_apiname"]);
                    $objTpl->setVariable("FORM_NOTES_VALUE", $_POST["frm_description"]);
                    $objTpl->setVariable("ERROR_MAIN", $objLang->get("main", "formerror"));
                } else {
                    //*** Input is valid. Save the template.
                    if ($strCommand == CMD_EDIT) {
                        $objTemplate = Template::selectByPK($intElmntId);
                    } else {
                        $objTemplate = new Template();
                        $objTemplate->setParentId($_POST["eid"]);
                        $objTemplate->setAccountId($_CONF['app']['account']->getId());
                    }
                    $objTemplate->setIsPage(empty($_CLEAN_POST["frm_ispage"]) ? 0 : 1);
                    $objTemplate->setIsContainer(empty($_CLEAN_POST["frm_iscontainer"]) ? 0 : 1);
                    $objTemplate->setForceCreation(empty($_CLEAN_POST["frm_forcecreation"]) ? 0 : 1);
                    $objTemplate->setName($_CLEAN_POST["frm_name"]);
                    $objTemplate->setApiName($_CLEAN_POST["frm_apiname"]);
                    $objTemplate->setDescription($_CLEAN_POST["frm_description"]);
                    $objTemplate->save();
                    header("Location: " . Request::getURI() . "/?cid=" . $_POST["cid"] . "&cmd=" . CMD_LIST . "&eid=" . $objTemplate->getId());
                    exit;
                }
            } else {
                $objTpl->setVariable("FORM_NAME", "templateForm");
            }
            //*** Parse the template.
            $objTemplate = Template::selectByPK($intElmntId);
            //*** Set section title.
            if ($strCommand == CMD_EDIT) {
                $objTpl->setVariable("MAINTITLE", $objLang->get("templateDetailsFor", "label"));
                $objTpl->setVariable("MAINSUB", $objTemplate->getName());
            } else {
                $objTpl->setVariable("MAINTITLE", $objLang->get("templateDetails", "label"));
            }
            //*** Set tab title.
            $objTpl->setCurrentBlock("headertitel_simple");
            $objTpl->setVariable("HEADER_TITLE", $objLang->get("details", "label"));
            $objTpl->parseCurrentBlock();
            $objTpl->setCurrentBlock("templateadd");
            //*** Insert values if action is edit.
            if ($strCommand == CMD_EDIT) {
                $objTpl->setVariable("FORM_ISPAGE_VALUE", $objTemplate->getIsPage() ? "checked=\"checked\"" : "");
                $objTpl->setVariable("FORM_ISCONTAINER_VALUE", $objTemplate->getIsContainer() ? "checked=\"checked\"" : "");
                $objTpl->setVariable("FORM_FORCECREATION_VALUE", $objTemplate->getForceCreation() ? "checked=\"checked\"" : "");
                $objTpl->setVariable("FORM_NAME_VALUE", $objTemplate->getName());
                $objTpl->setVariable("FORM_APINAME_VALUE", $objTemplate->getApiname());
                $objTpl->setVariable("FORM_NOTES_VALUE", $objTemplate->getDescription());
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$objTemplate->getParentId()}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$objTemplate->getParentId()}&amp;cmd=" . CMD_LIST);
            } else {
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
            }
            $objTpl->setVariable("LABEL_REQUIRED", $objLang->get("requiredFields", "form"));
            $objTpl->setVariable("LABEL_PAGECONTAINER", $objLang->get("pageContainer", "form"));
            $objTpl->setVariable("LABEL_ISCONTAINER", $objLang->get("container", "form"));
            $objTpl->setVariable("ISCONTAINER_NOTE", $objLang->get("containerNote", "tip"));
            $objTpl->setVariable("LABEL_FORCECREATION", $objLang->get("forceCreation", "form"));
            $objTpl->setVariable("FORCECREATION_NOTE", $objLang->get("forceCreationNote", "tip"));
            $objTpl->setVariable("LABEL_TEMPLATENAME", $objLang->get("templateName", "form"));
            $objTpl->setVariable("LABEL_NAME", $objLang->get("name", "form"));
            $objTpl->setVariable("APINAME_NOTE", $objLang->get("apiNameNote", "tip"));
            $objTpl->setVariable("LABEL_NOTES", $objLang->get("notes", "form"));
            $objTpl->parseCurrentBlock();
            $objTpl->setCurrentBlock("singleview");
            $objTpl->setVariable("BUTTON_CANCEL", $objLang->get("back", "button"));
            $objTpl->setVariable("BUTTON_FORMCANCEL", $objLang->get("cancel", "button"));
            $objTpl->setVariable("LABEL_SAVE", $objLang->get("save", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_TEMPLATES);
            $objTpl->setVariable("CMD", $strCommand);
            $objTpl->setVariable("EID", $intElmntId);
            $objTpl->parseCurrentBlock();
            break;
        case CMD_ADD_FIELD:
        case CMD_EDIT_FIELD:
            $objTpl->loadTemplatefile("templatefield.tpl.htm");
            //*** Post the templateField form if submitted.
            if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "addTemplateField") {
                //*** The template form has been posted.
                $blnError = false;
                //*** Check sanitized input.
                if (is_null($_CLEAN_POST["frm_required"])) {
                    $objTpl->setVariable("ERROR_REQUIRED_ON", " error");
                    $objTpl->setVariable("ERROR_REQUIRED", $objLang->get("commonTypeText", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_name"])) {
                    $objTpl->setVariable("ERROR_NAME_ON", " error");
                    $objTpl->setVariable("ERROR_NAME", $objLang->get("fieldName", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_apiname"])) {
                    $objTpl->setVariable("ERROR_APINAME_ON", " error");
                    $objTpl->setVariable("ERROR_APINAME", $objLang->get("commonTypeWord", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_description"])) {
                    $objTpl->setVariable("ERROR_NOTES_ON", " error");
                    $objTpl->setVariable("ERROR_NOTES", $objLang->get("commonTypeText", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_field_type"])) {
                    $objTpl->setVariable("ERROR_FIELDTYPE_ON", " error");
                    $objTpl->setVariable("ERROR_FIELDTYPE", $objLang->get("fieldType", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["dispatch"])) {
                    $blnError = true;
                }
                if ($blnError === true) {
                    //*** Display global error.
                    $objTpl->setVariable("FORM_NAME", "templateFieldForm");
                    $objTpl->setVariable("FORM_REQUIRED_VALUE", isset($_POST["frm_required"]) && $_POST["frm_required"] == "on" ? "checked=\"checked\"" : "");
                    $objTpl->setVariable("FORM_NAME_VALUE", $_POST["frm_name"]);
                    $objTpl->setVariable("FORM_APINAME_VALUE", $_POST["frm_apiname"]);
                    $objTpl->setVariable("FORM_NOTES_VALUE", $_POST["frm_description"]);
                    $objTpl->setVariable("ERROR_MAIN", $objLang->get("main", "formerror"));
                } else {
                    //*** Input is valid. Save the template.
                    if ($strCommand == CMD_EDIT_FIELD) {
                        $objField = TemplateField::selectByPK($intElmntId);
                    } else {
                        $objField = new TemplateField();
                        $objField->setTemplateId($_POST["eid"]);
                    }
                    $objField->setRequired(empty($_CLEAN_POST["frm_required"]) ? 0 : 1);
                    $objField->setName($_CLEAN_POST["frm_name"]);
                    $objField->setApiName($_CLEAN_POST["frm_apiname"]);
                    $objField->setDescription($_CLEAN_POST["frm_description"]);
                    $objField->setTypeId($_CLEAN_POST["frm_field_type"]);
                    $objField->setUsername($objLiveUser->getProperty("name"));
                    $objField->save();
                    $objField->clearValues();
                    //*** Add type values to the field.
                    foreach ($_REQUEST as $key => $value) {
                        if (is_array($value)) {
                            $intCount = 0;
                            foreach ($value as $subKey => $subValue) {
                                $objValue = new TemplateFieldValue();
                                $objValue->setName($key . "_" . $intCount);
                                $objValue->setValue($subValue);
                                $objValue->setFieldId($objField->getId());
                                $objValue->save();
                                $intCount++;
                            }
                        } else {
                            if ($value != "" && substr($key, 0, 4) == "tfv_") {
                                $objValue = new TemplateFieldValue();
                                $objValue->setName($key);
                                $objValue->setValue($value);
                                $objValue->setFieldId($objField->getId());
                                $objValue->save();
                            }
                        }
                    }
                    header("Location: " . Request::getURI() . "/?cid=" . $_POST["cid"] . "&cmd=" . CMD_LIST . "&eid=" . $objField->getTemplateId());
                    exit;
                }
            } else {
                $objTpl->setVariable("FORM_NAME", "templateFieldForm");
            }
            $objTpl->setCurrentBlock("headertitel_simple");
            $objTpl->setVariable("HEADER_TITLE", $objLang->get("details", "label"));
            $objTpl->parseCurrentBlock();
            $typeValue = 0;
            if ($strCommand == CMD_EDIT_FIELD) {
                $objField = TemplateField::selectByPK($intElmntId);
                $typeValue = $objField->getTypeId();
            }
            $objTypes = TemplateFieldTypes::getTypes();
            if (is_object($objTypes)) {
                foreach ($objTypes as $objType) {
                    $objTpl->setCurrentBlock("list_fieldtype");
                    if ($typeValue == $objType->getId()) {
                        $objTpl->setVariable("FIELDTYPE_SELECTED", "selected=\"selected\"");
                    }
                    $objTpl->setVariable("FIELDTYPE_VALUE", $objType->getId());
                    $objTpl->setVariable("FIELDTYPE_TEXT", xhtmlsave($objType->getName()));
                    $objTpl->parseCurrentBlock();
                }
            }
            //*** Set section title.
            if ($strCommand == CMD_EDIT_FIELD) {
                $objTpl->setVariable("MAINTITLE", $objLang->get("templateFieldDetailsFor", "label"));
                $objTpl->setVariable("MAINSUB", $objField->getName());
            } else {
                $objTpl->setVariable("MAINTITLE", $objLang->get("templateFieldDetails", "label"));
            }
            //*** Image crop settings.
            $arrValues = array(1, 2, 3, 4);
            $arrLabels = array("Resize cropped", "Resize fit cropped", "Resize distorted", "Resize to fit");
            $arrSettings = array();
            $arrImageSettings = array();
            if ($strCommand == CMD_EDIT_FIELD) {
                $objFieldValues = $objField->getValues();
                if (is_object($objFieldValues)) {
                    foreach ($objFieldValues as $objFieldValue) {
                        switch (strtoupper($objFieldValue->getName())) {
                            case "TFV_BOOLEAN_DEFAULT":
                                if ($objFieldValue->getValue()) {
                                    $arrSettings[$objFieldValue->getName()] = "checked=\"checked\"";
                                }
                                break;
                            default:
                                $arrKey = explode("_", $objFieldValue->getName());
                                $intIndex = array_pop($arrKey);
                                if (is_numeric($intIndex)) {
                                    $strValue = $objFieldValue->getValue();
                                    $arrImageSettings[$intIndex][implode("_", $arrKey)] = xhtmlsave($strValue);
                                } else {
                                    $strValue = $objFieldValue->getValue();
                                    $arrSettings[$objFieldValue->getName()] = xhtmlsave($strValue);
                                }
                        }
                    }
                    if (count($arrImageSettings) > 0) {
                        //*** Image settings.
                        $arrImageSettings = array_reverse($arrImageSettings);
                        foreach ($arrImageSettings as $key => $objValue) {
                            $objTpl->setCurrentBlock("image.settings");
                            foreach ($objValue as $setting => $value) {
                                switch (strtoupper($setting)) {
                                    case "TFV_IMAGE_SCALE":
                                        $strValue = "";
                                        foreach ($arrValues as $settingKey => $settingValue) {
                                            $selected = $settingValue == $value ? " selected=\"selected\"" : "";
                                            $strValue .= "<option value=\"{$arrValues[$settingKey]}\"{$selected}>{$arrLabels[$settingKey]}</option>\n";
                                        }
                                        $objTpl->setVariable(strtoupper($setting), $strValue);
                                        break;
                                    case "TFV_IMAGE_GRAYSCALE":
                                        if ($value) {
                                            $objTpl->setVariable(strtoupper($setting), "checked=\"checked\"");
                                        }
                                        break;
                                    default:
                                        $objTpl->setVariable(strtoupper($setting), xhtmlsave($value));
                                }
                            }
                            if (count($arrImageSettings) == 1) {
                                $objTpl->setVariable("API_STYLE", "display:none");
                            }
                            if ($key == 0) {
                                $objTpl->setVariable("REMOVE_STYLE", "display:none");
                            }
                            $objTpl->parseCurrentBlock();
                        }
                    }
                }
            }
            $objTpl->setCurrentBlock("templatefieldadd");
            $objTpl->setVariable("LABEL_REQUIRED", $objLang->get("requiredFields", "form"));
            $objTpl->setVariable("LABEL_REQUIREDFIELD", $objLang->get("requiredField", "form"));
            $objTpl->setVariable("LABEL_FIELDNAME", $objLang->get("fieldName", "form"));
            $objTpl->setVariable("LABEL_NAME", $objLang->get("name", "form"));
            $objTpl->setVariable("APINAME_NOTE", $objLang->get("apiNameNote", "tip"));
            $objTpl->setVariable("LABEL_NOTES", $objLang->get("notes", "form"));
            $objTpl->setVariable("LABEL_FIELDTYPE", $objLang->get("fieldType", "form"));
            $objTpl->setVariable("LABEL_FIELDTYPE_OPTIONS", $objLang->get("typeOptions", "label"));
            $objTpl->setVariable("TFV_LIST_NOTES", $objLang->get("templateListType", "tip"));
            $objTpl->setVariable("TFV_FORMAT_NOTES", $objLang->get("templateDateType", "tip"));
            $objTpl->setVariable("TFV_QUALITY_NOTES", $objLang->get("templateImageType", "tip"));
            $objTpl->setVariable("TFV_EXTENSION_NOTES", $objLang->get("templateFileType", "tip"));
            //*** Render image scale pulldown.
            if (count($arrImageSettings) == 0) {
                $strValue = "";
                foreach ($arrValues as $key => $value) {
                    $strValue .= "<option value=\"{$arrValues[$key]}\">{$arrLabels[$key]}</option>\n";
                }
                $objTpl->setVariable("TFV_IMAGE_SCALE", $strValue);
                $objTpl->setVariable("API_STYLE", "display:none");
                $objTpl->setVariable("REMOVE_STYLE", "display:none");
            }
            //*** Insert values if action is edit.
            if ($strCommand == CMD_EDIT_FIELD) {
                $objTpl->setVariable("FORM_REQUIRED_VALUE", $objField->getRequired() ? "checked=\"checked\"" : "");
                $objTpl->setVariable("FORM_NAME_VALUE", $objField->getName());
                $objTpl->setVariable("FORM_APINAME_VALUE", $objField->getApiname());
                $objTpl->setVariable("FORM_NOTES_VALUE", $objField->getDescription());
                //*** Insert values for the field type.
                if (count($arrSettings) > 0) {
                    foreach ($arrSettings as $name => $value) {
                        switch (strtoupper($name)) {
                            case "TFV_BOOLEAN_DEFAULT":
                                if ($value) {
                                    $objTpl->setVariable(strtoupper($name), "checked=\"checked\"");
                                }
                                break;
                            case "TFV_IMAGE_SCALE":
                                //*** Skip. Already set.
                                break;
                            default:
                                $objTpl->setVariable(strtoupper($name), xhtmlsave($value));
                        }
                    }
                }
            }
            $objTpl->parseCurrentBlock();
            $objTpl->setCurrentBlock("singleview");
            if ($strCommand == CMD_EDIT_FIELD) {
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$objField->getTemplateId()}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$objField->getTemplateId()}&amp;cmd=" . CMD_LIST);
            } else {
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
            }
            $objTpl->setVariable("BUTTON_CANCEL", $objLang->get("back", "button"));
            $objTpl->setVariable("BUTTON_FORMCANCEL", $objLang->get("cancel", "button"));
            $objTpl->setVariable("LABEL_SAVE", $objLang->get("save", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_TEMPLATES);
            $objTpl->setVariable("CMD", $strCommand);
            $objTpl->setVariable("EID", $intElmntId);
            $objTpl->parseCurrentBlock();
            break;
        case CMD_ADD_STRUCTURE:
        case CMD_ADD_STRUCTURE_DETAIL:
            $objTpl->loadTemplatefile("structure.tpl.htm");
            $blnRenderSelects = false;
            //*** Post the structure form if submitted.
            if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "addStructure") {
                //*** The structure form has been posted.
                $blnError = false;
                //*** Check sanitized input.
                if (is_null($_CLEAN_POST["frm_structure"])) {
                    $objTpl->setVariable("ERROR_STRUCTURE_ON", " error");
                    $objTpl->setVariable("ERROR_STRUCTURE", $objLang->get("structure", "formerror"));
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["dispatch"])) {
                    $blnError = true;
                }
                if ($blnError === true) {
                    //*** Display global error.
                    $objTpl->setVariable("FORM_NAME", "structureForm");
                    $objTpl->setVariable("ERROR_MAIN", $objLang->get("main", "formerror"));
                } else {
                    //*** Input is valid. Import the structure.
                    if (Structure::hasSelect($_CLEAN_POST["frm_structure"]) && $strCommand == CMD_ADD_STRUCTURE) {
                        $blnRenderSelects = true;
                    } else {
                        Structure::addById($_CLEAN_POST["frm_structure"], $intElmntId);
                        header("Location: " . Request::getURI() . "/?cid=" . $_POST["cid"] . "&cmd=" . CMD_LIST . "&eid=" . $intElmntId);
                        exit;
                    }
                }
            } else {
                $objTpl->setVariable("FORM_NAME", "structureForm");
            }
            //*** Parse the template.
            $objTemplate = Template::selectByPK($intElmntId);
            //*** Set section title.
            $objTpl->setVariable("MAINTITLE", $objLang->get("structureAdd", "label"));
            //*** Set tab title.
            $objTpl->setCurrentBlock("headertitel_simple");
            $objTpl->setVariable("HEADER_TITLE", $objLang->get("structureDetails", "label"));
            $objTpl->parseCurrentBlock();
            if (!$blnRenderSelects) {
                $objElements = Structure::selectBySection("template");
                foreach ($objElements as $objElement) {
                    $objTpl->setCurrentBlock("structure.item");
                    $objTpl->setVariable("VALUE", $objElement->getId());
                    $objTpl->setVariable("LABEL", $objElement->getName());
                    $objTpl->parseCurrentBlock();
                }
                foreach ($objElements as $objElement) {
                    $objTpl->setCurrentBlock("structure.description");
                    $objTpl->setVariable("VALUE", $objElement->getId());
                    $objTpl->setVariable("BODY", $objElement->getDescription());
                    if ($objElements->key() > 0) {
                        $objTpl->setVariable("HIDE", "display:none");
                    }
                    $objTpl->parseCurrentBlock();
                }
                $objTpl->setCurrentBlock("structureadd.description");
                $objTpl->setVariable("LABEL_REQUIRED", $objLang->get("structureAdd", "tip"));
                $objTpl->parseCurrentBlock();
                $objTpl->setCurrentBlock("structureadd");
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("LABEL_STRUCTURENAME", $objLang->get("structureName", "form"));
                $objTpl->parseCurrentBlock();
            } else {
                $objSelects = Structure::getSelectsById($_CLEAN_POST["frm_structure"]);
                foreach ($objSelects as $objSelect) {
                    switch ($objSelect->getType()) {
                        case "language":
                            $objContentLangs = ContentLanguage::select();
                            foreach ($objContentLangs as $objContentLang) {
                                $objTpl->setCurrentBlock("select.language.item");
                                $objTpl->setVariable("LABEL", $objContentLang->getName());
                                $objTpl->setVariable("VALUE", $objContentLang->getId());
                                $objTpl->parseCurrentBlock();
                            }
                            $objTpl->setCurrentBlock("select.language");
                            $objTpl->setVariable("LABEL", $objLang->get("sSelectLanguage", "form"));
                            $objTpl->setVariable("DESCRIPTION", $objSelect->getDescription());
                            $objTpl->setVariable("SELECT_NAME", "frm_select_" . $objSelect->getId());
                            $objTpl->parseCurrentBlock();
                            break;
                        case "element":
                            $objTpl->setCurrentBlock("select.element");
                            $objTpl->setVariable("DESCRIPTION", $objSelect->getDescription());
                            $objTpl->setVariable("SELECT_NAME", "frm_select_" . $objSelect->getId());
                            $objTpl->setVariable("FORM_NAME", "detailsForm");
                            $objTpl->parseCurrentBlock();
                            break;
                    }
                }
                $objTpl->setCurrentBlock("structureadd.description");
                $objTpl->setVariable("LABEL_REQUIRED", $objLang->get("structureSelects", "tip"));
                $objTpl->parseCurrentBlock();
                $objTpl->setCurrentBlock("structureselects");
                $objTpl->setVariable("FRM_STRUCURE", $_CLEAN_POST["frm_structure"]);
                $objTpl->parseCurrentBlock();
                $objTpl->setVariable("BUTTON_CANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
                $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
            }
            $objTpl->setCurrentBlock("singleview");
            $objTpl->setVariable("BUTTON_CANCEL", $objLang->get("back", "button"));
            $objTpl->setVariable("BUTTON_FORMCANCEL", $objLang->get("cancel", "button"));
            $objTpl->setVariable("LABEL_SAVE", $objLang->get("insert", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_TEMPLATES);
            $objTpl->setVariable("CMD", !$blnRenderSelects ? CMD_ADD_STRUCTURE : CMD_ADD_STRUCTURE_DETAIL);
            $objTpl->setVariable("EID", $intElmntId);
            $objTpl->parseCurrentBlock();
            if ($blnRenderSelects) {
                $objTpl->setVariable("FORM_NAME", "detailsForm");
            }
            break;
        case CMD_EXPORT_TEMPLATE:
            $objTpl->loadTemplatefile("export.tpl.htm");
            //*** Parse the template.
            $objTemplate = Template::selectByPK($intElmntId);
            //*** Set section title.
            $objTpl->setVariable("MAINTITLE", $objLang->get("export", "label"));
            //*** Set tab title.
            $objTpl->setCurrentBlock("headertitel_simple");
            $objTpl->setVariable("HEADER_TITLE", $objLang->get("exportOptions", "label"));
            $objTpl->parseCurrentBlock();
            $objTpl->setVariable("FORM_NAME", "exportForm");
            //*** Handle request & create export
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['export_type'])) {
                //*** The template form has been posted.
                $arrTemplateFilters = array();
                foreach ($_POST['tmpl'] as $id => $val) {
                    $arrTemplateFilters[] = intval($id);
                }
                $exportElements = $_POST['export_type'] == 'templates_elements' ? true : false;
                $strZipFile = ImpEx::exportFrom(NULL, $objTemplate->getId(), NULL, $arrTemplateFilters, $_CONF['app']['account']->getId(), $exportElements);
                //*** Return XML.
                header("HTTP/1.1 200 OK");
                header("Pragma: public");
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                header("Cache-Control: private", false);
                header('Content-Type: application/octetstream; charset=utf-8');
                header("Content-Length: " . (string) filesize($strZipFile));
                header('Content-Disposition: attachment; filename="' . date("Y-m-d") . '_exportTemplates.zip"');
                header("Content-Transfer-Encoding: binary\n");
                readfile($strZipFile);
                unlink($strZipFile);
                exit;
            }
            //*** Create template checkboxes
            $objTpl->setVariable("FORM_CHECKBOXES", createTemplateTree($objTemplate));
            $objTpl->setVariable("EXPORT", $objLang->get("export", "label"));
            $objTpl->setVariable("EXPORT_TEMPLATES_ELEMENTS", $objLang->get("templatesElements", "label"));
            $objTpl->setVariable("EXPORT_TEMPLATES", $objLang->get("templates", "label"));
            $objTpl->setVariable("SELECT_ITEMS", $objLang->get("selectTemplates", "label"));
            //*** Set form buttons
            $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
            $objTpl->setCurrentBlock("singleview");
            $objTpl->setVariable("BUTTON_CANCEL", $objLang->get("back", "button"));
            $objTpl->setVariable("BUTTON_FORMCANCEL", $objLang->get("cancel", "button"));
            $objTpl->setVariable("LABEL_SAVE", $objLang->get("export", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_TEMPLATES);
            $objTpl->setVariable("CMD", CMD_EXPORT_TEMPLATE);
            $objTpl->setVariable("EID", $intElmntId);
            $objTpl->parseCurrentBlock();
            break;
        case CMD_IMPORT_TEMPLATE:
            $objTpl->loadTemplatefile("import.tpl.htm");
            //*** Parse the template.
            $objTemplate = Template::selectByPK($intElmntId);
            //*** Set section title.
            $objTpl->setVariable("MAINTITLE", $objLang->get("import", "label"));
            //*** Set tab title.
            $objTpl->setCurrentBlock("headertitel_simple");
            $objTpl->setVariable("HEADER_TITLE", $objLang->get("importOptions", "label"));
            $objTpl->parseCurrentBlock();
            //*** Handle request & do import
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_FILES["file"]["name"])) {
                if ($_FILES["file"]["error"] > 0) {
                    $objTpl->setVariable('ERROR_MAIN', 'Error: ' . $_FILES["file"]["error"]);
                } else {
                    if (end(explode(".", $_FILES["file"]["name"])) !== 'zip') {
                        $objTpl->setVariable('ERROR_MAIN', 'Error: Only *.ZIP files allowed');
                    } else {
                        $importElements = $_POST['import_type'] === 'templates_elements' ? true : false;
                        if (!ImpEx::importIn($_FILES["file"]["tmp_name"], NULL, $objTemplate->getId(), $_CONF['app']['account']->getId(), true, $importElements, false)) {
                            $objTpl->setVariable('ERROR_MAIN', 'Templates and/or fields of templates in file do not match the destination templates');
                        }
                    }
                }
            }
            $objTpl->setVariable("IMPORT", $objLang->get("import", "label"));
            $objTpl->setVariable("IMPORT_TEMPLATES_ELEMENTS", $objLang->get("templatesElements", "label"));
            $objTpl->setVariable("IMPORT_TEMPLATES", $objLang->get("templates", "label"));
            $objTpl->setVariable("IMPORT_ELEMENTS", $objLang->get("elements", "label"));
            $objTpl->setVariable('CUR_LOCATION', $objTemplate->getName());
            $objTpl->setVariable("IMPORT_FILE", $objLang->get("importFile", "label"));
            $objTpl->setVariable("IMPORT_FILE_TIP", $objLang->get("importFile", "tip"));
            //*** Set form buttons
            $objTpl->setVariable("BUTTON_FORMCANCEL_HREF", "?cid=" . NAV_PCMS_TEMPLATES . "&amp;eid={$intElmntId}&amp;cmd=" . CMD_LIST);
            $objTpl->setCurrentBlock("singleview");
            $objTpl->setVariable("BUTTON_CANCEL", $objLang->get("back", "button"));
            $objTpl->setVariable("BUTTON_FORMCANCEL", $objLang->get("cancel", "button"));
            $objTpl->setVariable("LABEL_SAVE", $objLang->get("import", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_TEMPLATES);
            $objTpl->setVariable("CMD", CMD_IMPORT_TEMPLATE);
            $objTpl->setVariable("EID", $intElmntId);
            $objTpl->parseCurrentBlock();
            break;
    }
    return $objTpl->get();
}
Example #17
0
 /**
  * @role save
  */
 public function save()
 {
     $request = $this->getRequest();
     $code = $request->get('code');
     if ($this->request->get('fileName')) {
         $fileName = $this->request->get('fileName');
         if (strtolower(substr($fileName, -4)) != '.tpl') {
             $fileName .= '.tpl';
         }
         $template = new Template($fileName, $this->request->get('theme'));
     } else {
         $template = new Template($this->getFileName(), $this->request->get('theme'));
     }
     $origPath = $this->getFileName();
     if ($template->isCustomFile() && !$this->request->get('new') && $template->getFileName() != $origPath && !$this->request->get('theme')) {
         $origPath = Template::getCustomizedFilePath($origPath);
         if (file_exists($origPath)) {
             unlink($origPath);
         }
     }
     $template->setCode($code);
     $res = $template->save();
     if ($res) {
         return new JSONResponse(array('template' => $template->toArray(), 'isNew' => $this->request->get('new')), 'success', $this->translate('_template_has_been_successfully_updated'));
     } else {
         return new JSONResponse(false, 'failure', $this->translate('_could_not_update_template'));
     }
 }
<?php

$type = $_REQUEST['type'];
require 'Template.php';
require 'usermessage.php';
//used to send message to compent component in page.
switch ($type) {
    case 'new':
        $templateName = $_REQUEST['name'];
        $t = new Template();
        $t->newTemplate($templateName, false);
        $t->save();
        usermessage("Template Created successfuly");
        break;
    default:
        usermessage("An Error Occured.");
        break;
}
 public function newTemplate()
 {
     try {
         $model = new Template();
         $this->data->template->entry = 'tpl_' . $this->data->template->entry;
         $model->setData($this->data->template);
         $model->save();
         $this->renderPrompt('information', 'OK', "structure.editEntry('{$this->data->template->entry}');");
     } catch (\Exception $e) {
         $this->renderPrompt('error', $e->getMessage());
     }
 }
Example #20
0
 function create($vars, &$errors)
 {
     return Template::save(0, $vars, $errors);
 }
 /**
  * Install the module and related modules
  *
  */
 public function ___install()
 {
     $configData = array();
     if ($this->templates->get(LanguageSupport::languageTemplateName)) {
         throw new WireException("There is already a template installed called 'language'");
     }
     if ($this->fields->get(LanguageSupport::languageFieldName)) {
         throw new WireException("There is already a field installed called 'language'");
     }
     $adminPage = $this->pages->get($this->config->adminRootPageID);
     $setupPage = $adminPage->child("name=setup");
     if (!$setupPage->id) {
         throw new WireException("Unable to locate {$adminPage->path}setup/");
     }
     // create the languages parent page
     $languagesPage = new Page();
     $languagesPage->parent = $setupPage;
     $languagesPage->template = $this->templates->get('admin');
     $languagesPage->process = $this->modules->get('ProcessLanguage');
     // INSTALL ProcessLanguage module
     $this->message("Installed ProcessLanguage");
     $languagesPage->name = 'languages';
     $languagesPage->title = 'Languages';
     $languagesPage->status = Page::statusSystem;
     $languagesPage->sort = $setupPage->numChildren;
     $languagesPage->save();
     $configData['languagesPageID'] = $languagesPage->id;
     // create the 'language_files' field used by the 'language' fieldgroup
     $field = new Field();
     $field->type = $this->modules->get("FieldtypeFile");
     $field->name = 'language_files';
     $field->label = 'Language Translation Files';
     $field->extensions = 'json';
     $field->maxFiles = 0;
     $field->inputfieldClass = 'InputfieldFile';
     $field->unzip = 1;
     $field->descriptionRows = 1;
     $field->flags = Field::flagSystem | Field::flagPermanent;
     $field->save();
     $this->message("Created field: language_files");
     // create the fieldgroup to be used by the language template
     $fieldgroup = new Fieldgroup();
     $fieldgroup->name = LanguageSupport::languageTemplateName;
     $fieldgroup->add($this->fields->get('title'));
     $fieldgroup->add($field);
     // language_files
     $fieldgroup->save();
     $this->message("Created fieldgroup: " . LanguageSupport::languageTemplateName . " ({$fieldgroup->id})");
     // create the template used by Language pages
     $template = new Template();
     $template->name = LanguageSupport::languageTemplateName;
     $template->fieldgroup = $fieldgroup;
     $template->parentTemplates = array($adminPage->template->id);
     $template->slashUrls = 1;
     $template->pageClass = 'Language';
     $template->pageLabelField = 'name';
     $template->noGlobal = 1;
     $template->noMove = 1;
     $template->noTrash = 1;
     $template->noUnpublish = 1;
     $template->noChangeTemplate = 1;
     $template->nameContentTab = 1;
     $template->flags = Template::flagSystem;
     $template->save();
     $this->message("Created Template: " . LanguageSupport::languageTemplateName);
     // create the default language page
     $default = new Language();
     $default->template = $template;
     $default->parent = $languagesPage;
     $default->name = 'default';
     $default->title = 'Default';
     $default->status = Page::statusSystem;
     $default->save();
     $configData['defaultLanguagePageID'] = $default->id;
     $configData['otherLanguagePageIDs'] = array();
     // non-default language IDs placeholder
     $this->message("Created Default Language Page: {$default->path}");
     // create the translator page and process
     $translatorPage = new Page();
     $translatorPage->parent = $setupPage;
     $translatorPage->template = $this->templates->get('admin');
     $translatorPage->status = Page::statusHidden | Page::statusSystem;
     $translatorPage->process = $this->modules->get('ProcessLanguageTranslator');
     // INSTALL ProcessLanguageTranslator
     $this->message("Installed ProcessLanguageTranslator");
     $translatorPage->name = 'language-translator';
     $translatorPage->title = 'Language Translator';
     $translatorPage->save();
     $configData['languageTranslatorPageID'] = $translatorPage->id;
     $this->message("Created Language Translator Page: {$translatorPage->path}");
     // save the module config data
     $this->modules->saveModuleConfigData('LanguageSupport', $configData);
     // install 'language' field that will be added to the user fieldgroup
     $field = new Field();
     $field->type = $this->modules->get("FieldtypePage");
     $field->name = LanguageSupport::languageFieldName;
     $field->label = 'Language';
     $field->derefAsPage = 1;
     $field->parent_id = $languagesPage->id;
     $field->labelFieldName = 'title';
     $field->inputfield = 'InputfieldRadios';
     $field->required = 1;
     $field->flags = Field::flagSystem | Field::flagPermanent;
     $field->save();
     $this->message("Created Langage Field: " . LanguageSupport::languageFieldName);
     // make the 'language' field part of the profile fields the user may edit
     $profileConfig = $this->modules->getModuleConfigData('ProcessProfile');
     $profileConfig['profileFields'][] = 'language';
     $this->modules->saveModuleConfigData('ProcessProfile', $profileConfig);
     // add to 'user' fieldgroup
     $userFieldgroup = $this->templates->get('user')->fieldgroup;
     $userFieldgroup->add($field);
     $userFieldgroup->save();
     $this->message("Added field 'language' to user profile");
     // update all users to have the default value set for this field
     $n = 0;
     foreach ($this->users as $user) {
         $user->set('language', $default);
         $user->save();
         $n++;
     }
     $this->message("Added default language to {$n} user profiles");
     $this->message("Language Support Installed! Click to the 'Setup' menu to begin defining languages.");
 }
Example #22
0
 public static function importTemplates($objTemplates, $intAccountId, &$arrTemplateIds, &$arrTemplateFieldIds, &$arrLinkFieldIds, $intParentId = 0)
 {
     foreach ($objTemplates->childNodes as $templateNode) {
         $objTemplate = new Template();
         $objTemplate->setAccountId($intAccountId);
         $objTemplate->setParentId($intParentId);
         $objTemplate->setIsPage($templateNode->getAttribute("isPage"));
         $objTemplate->setIsContainer($templateNode->getAttribute("isContainer"));
         $objTemplate->setForceCreation($templateNode->getAttribute("forceCreation"));
         $objTemplate->setName($templateNode->getAttribute("name"));
         $objTemplate->setApiName($templateNode->getAttribute("apiName"));
         $objTemplate->setDescription($templateNode->getAttribute("description"));
         $objTemplate->setSort($templateNode->getAttribute("sort"));
         $objTemplate->save();
         $arrTemplateIds[$templateNode->getAttribute("id")] = $objTemplate->getId();
         //*** Add fields to the template.
         foreach ($templateNode->childNodes as $fieldsNode) {
             switch ($fieldsNode->nodeName) {
                 case "fields":
                     foreach ($fieldsNode->childNodes as $fieldNode) {
                         $objField = new TemplateField();
                         $objField->setTemplateId($objTemplate->getId());
                         $objField->setRequired($fieldNode->getAttribute("required"));
                         $objField->setName($fieldNode->getAttribute("name"));
                         $objField->setApiName($fieldNode->getAttribute("apiName"));
                         $objField->setDescription($fieldNode->getAttribute("description"));
                         $objField->setTypeId($fieldNode->getAttribute("typeId"));
                         $objField->setUsername($fieldNode->getAttribute("username"));
                         $objField->setSort($fieldNode->getAttribute("sort"));
                         $objField->save();
                         $arrTemplateFieldIds[$fieldNode->getAttribute("id")] = $objField->getId();
                         if ($fieldNode->getAttribute("typeId") == FIELD_TYPE_LINK) {
                             array_push($arrLinkFieldIds, $fieldNode->getAttribute("id"));
                         }
                         //*** Add values to the field.
                         foreach ($fieldNode->childNodes as $valuesNode) {
                             switch ($valuesNode->nodeName) {
                                 case "values":
                                     foreach ($valuesNode->childNodes as $valueNode) {
                                         $objValue = new TemplateFieldValue();
                                         $objValue->setName($valueNode->getAttribute("name"));
                                         $objValue->setValue($valueNode->getAttribute("value"));
                                         $objValue->setFieldId($objField->getId());
                                         $objValue->save();
                                     }
                                     break;
                             }
                         }
                     }
                     break;
                 case "templates":
                     self::importTemplates($fieldsNode, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds, $objTemplate->getId());
                     break;
             }
         }
     }
 }
Example #23
0
 /**
  * @Route("/createTemplate", methods = {"POST", "OPTIONS"})
  */
 public function CreateTemplateAction()
 {
     $info = $this->request->getJsonRawBody();
     if (!isset($info->handler_id) || !isset($info->name) || !isset($info->subject) || !isset($info->body)) {
         $this->response->setJsonContent(['message' => 'No Data!']);
         $this->response->send();
         return;
     }
     $template = new Template();
     $template->handler_id = $info->handler_id;
     $template->name = base64_encode($info->name);
     $template->subject = base64_encode($info->subject);
     $template->body = base64_encode($info->body);
     $template->save();
     $this->response->setJsonContent(['template_id' => $template->id, 'handler_id' => $info->handler_id, 'name' => $info->name, 'subject' => $info->subject, 'body' => $info->body]);
     $this->response->send();
     return;
 }
 public function install(array $settings)
 {
     $field = $this->fields->get('email_images');
     if (!$field) {
         $field = new Field();
         $field->name = 'email_images';
         $field->type = $this->modules->get('FieldtypeImage');
         $field->label = 'Email Images';
         $field->extensions = 'jpeg jpg gif png';
         $field->maxFiles = 0;
         $field->unzip = 0;
         $field->descriptionRows = 1;
         $field->entityEncode = 1;
         $field->save();
         $this->message("Created field: {$field->name}");
     }
     $settings['images_field_id'] = $field->id;
     $field2 = $this->fields->get('email_image_body');
     if (!$field2) {
         $field2 = new Field();
         $field2->name = 'email_image_body';
         $field2->type = $this->modules->get('FieldtypeTextarea');
         $field2->label = 'Body Text';
         $field2->textformatters = array('TextformatterEntities');
         $field2->inputfieldClass = 'InputfieldTextarea';
         $field2->rows = 5;
         $field2->save();
         $this->message("Created field: {$field2->name}");
     }
     // parent fieldgroup
     $parentFieldgroup = $this->fieldgroups->get('email-images');
     if (!$parentFieldgroup) {
         $parentFieldgroup = new Fieldgroup();
         $parentFieldgroup->name = 'email-images';
         $parentFieldgroup->save();
         $parentFieldgroup->add('title');
         $parentFieldgroup->save();
         $this->message("Created fieldgroup: {$parentFieldgroup->name}");
     }
     // parent template
     $parentTemplate = $this->templates->get('email-images');
     if (!$parentTemplate) {
         $parentTemplate = new Template();
         $parentTemplate->name = 'email-images';
         $parentTemplate->fieldgroup = $parentFieldgroup;
         $parentTemplate->allowPageNum = 1;
         $parentTemplate->save();
         $this->message("Created template: {$parentTemplate->name}");
     }
     $settings['parent_template_id'] = $parentTemplate->id;
     // child fieldgroup
     $childFieldgroup = $this->fieldgroups->get('email-image');
     if (!$childFieldgroup) {
         $childFieldgroup = new Fieldgroup();
         $childFieldgroup->name = 'email-image';
         $childFieldgroup->save();
         $childFieldgroup->add('title');
         $childFieldgroup->add($field);
         // email_images
         $childFieldgroup->add($field2);
         // email_image_body
         $childFieldgroup->save();
         $this->message("Created fieldgroup: {$childFieldgroup->name}");
     }
     // child template
     $childTemplate = $this->templates->get('email-image');
     if (!$template) {
         $childTemplate = new Template();
         $childTemplate->name = 'email-image';
         $childTemplate->fieldgroup = $childFieldgroup;
         $childTemplate->noChildren = 1;
         $childTemplate->parentTemplates = array($parentTemplate->id);
         $childTemplate->save();
         $this->message("Created template: {$childTemplate->name}");
     }
     $settings['child_template_id'] = $childTemplate->id;
     $parentPage = $this->pages->get('/email-images/');
     if (!$parentPage->id) {
         $parentPage = new Page();
         $parentPage->template = $parentTemplate;
         $parentPage->parent = '/';
         $parentPage->name = 'email-images';
         $parentPage->title = 'Email Images';
         $parentPage->addStatus(Page::statusHidden);
         $parentPage->sortfield = '-created';
         $parentPage->save();
         $this->message("Created page: {$parentPage->path}");
     }
     $settings['parent_page_id'] = $parentPage->id;
     // update settings for parentTemplate
     $parentTemplate->childTemplates = array($childTemplate->id);
     $parentTemplate->noParents = 1;
     $parentTemplate->save();
     $this->modules->saveModuleConfigData('EmailImage', $settings);
     // install template file
     if (is_writable(wire('config')->paths->templates)) {
         if (@copy(dirname(__FILE__) . '/email-images.php', wire('config')->paths->templates . 'email-images.php')) {
             $this->message("Installed template file: email-images.php");
         }
     }
 }
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/config/common.inc.php";
if (isset($_REQUEST['template_id'])) {
    // Parse response XML
    $xml = simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']);
    // updates local template in database
    $template = new Template();
    if ($template->load("id=\"" . mysql_escape_string(trim($_REQUEST['template_id'])) . "\"")) {
        error_log("updating " . $_REQUEST['template_id'] . " with RS ID of " . $xml->guid);
        $template->rs_template_id = $xml->guid;
        $template->save();
    } else {
        error_log("cannot find template with " . $_REQUEST['template_id']);
    }
} else {
    error_log("Warning no template_id found in the url for the following Data:");
    error_log($GLOBALS['HTTP_RAW_POST_DATA']);
}
Example #26
0
 public function saveTemplate($truth_name, $tpl_name = '', $temptype = 0)
 {
     if ($tpl_name != '') {
         $tpl_exists = Template::where('name', $tpl_name)->first();
         if ($tpl_exists) {
             $unpack_resuslt = $this->unpack($truth_name, $tpl_name, true, $temptype);
         } else {
             $tpl_exists = false;
             $unpack_resuslt = $this->unpack($truth_name, $tpl_name, true, $temptype);
         }
     } else {
         $tpl_exists = false;
         $unpack_resuslt = $this->unpack($truth_name, $tpl_name, false, $temptype);
     }
     if ($unpack_resuslt) {
         $tpl_info = $unpack_resuslt['config'];
         if ($tpl_exists) {
             $template = Template::find($tpl_exists->id);
         } else {
             $template = new Template();
             $template->name = $unpack_resuslt['tpl_dir'];
             $template->tpl_num = $unpack_resuslt['tpl_num'];
         }
         $template->tpl_name = $tpl_info['template']['tpl_name'];
         $template->classify = $tpl_info['template']['classify'];
         $template->demo = $tpl_info['template']['demo'];
         $template->type = $tpl_info['template']['type'];
         $template->description = $tpl_info['template']['description'];
         $template->list1showtypetotal = $tpl_info['template']['list1showtypetotal'];
         $template->list2showtypetotal = $tpl_info['template']['list2showtypetotal'];
         $template->list3showtypetotal = $tpl_info['template']['list3showtypetotal'];
         $template->list4showtypetotal = $tpl_info['template']['list4showtypetotal'];
         $template->updated_at = date("Y-m-d H:i:s", time());
         $insert_rst = $template->save();
         if ($insert_rst) {
             $insert_id = $template->id;
             $color_arr = $tpl_info['tpl_color'];
             $tpl_color = array();
             $i = 0;
             TemplateToColor::where('template_id', $insert_id)->delete();
             if (count($color_arr) > 0) {
                 foreach ($color_arr as $color) {
                     $tpl_color[$i]['template_id'] = $insert_id;
                     $tpl_color[$i]['color_code'] = Config::get('color.' . $color);
                     $tpl_color[$i]['color_id'] = Color::where('color_en', $color)->pluck('id');
                     $i++;
                 }
                 TemplateToColor::insert($tpl_color);
             }
         }
         $result = ['err' => 1000, 'msg' => '上传模板成功'];
     } else {
         $result = ['err' => 1003, 'msg' => '解压文件失败'];
     }
     return $result;
 }
Example #27
0
<?php

//Imports
require_once 'session.php';
require_once 'db/db_conn.php';
require_once 'db/SELECT.php';
require_once 'db/INSERT.php';
require_once 'classes/Template.php';
$con = connect_db();
$ADK_MSG_TMPL = new Template();
$ADK_MSG_TMPL->populateFromSave();
if (!$ADK_MSG_TMPL->isValid()) {
    $con->close();
    http_response_code(400);
    echo $ADK_MSG_TMPL->err;
    exit;
}
if (isset($_POST['isPrivate']) && $_POST['isPrivate'] == 'false') {
    $ADK_MSG_TMPL->userid = null;
}
$ADK_MSG_TMPL->sanitize();
$ADK_MSG_TMPL->save($con);
$ADK_MSG_TMPLS = new Templates();
$ADK_MSG_TMPLS->get($con, $_SESSION['ADK_USER_ID']);
$con->close();
echo json_encode($ADK_MSG_TMPLS);
http_response_code(200);
<?php

//
// Imports RightSignature's Templates into local templates in database
//
ob_start();
require_once $_SERVER['DOCUMENT_ROOT'] . "/config/common.inc.php";
// Calls API to get templates XML and parses it
$templates_xml = simplexml_load_string($rightsignature->getTemplates());
// Loops through each template node and copies guid
foreach ($templates_xml->templates->template as $template_node) {
    $template = new Template();
    if ($template->load("rs_template_id=\"" . mysql_escape_string(trim((string) $template_node->guid)) . "\"")) {
        error_log("Found template with RS guid of" . (string) $template_node->guid . " will not import");
    } else {
        error_log("Cannot find template with RS guid of" . (string) $template_node->guid . " importing...");
        $template->rs_template_id = (string) $template_node->guid;
        if ($template->save()) {
            error_log("successfully saved to {$template->id}");
        } else {
            error_log("cannot save template");
        }
    }
}
ob_flush();
Example #29
0
 private function _refreshtemplates()
 {
     $template_a = getTemplateList();
     foreach ($template_a as $tp => $fullpath) {
         // check for each folder if there is already an entry in the database
         // if not create it with current user as creator (user with rights "create user" can assign template rights)
         $result = Template::model()->findByPk($tp);
         if (count($result) == 0) {
             $post = new Template();
             $post->folder = $tp;
             $post->creator = Yii::app()->session['loginID'];
             $post->save();
         }
     }
     return true;
 }
 /**
  * Store a newly created template in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Template::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         $template = new Template();
         $template->color = Input::get('color');
         $template->layout = Input::get('templateID');
         $template->user_id = Auth::id();
         $template->save();
         //Storing header info
         if (Input::has('headerJobTitle')) {
             $header = new Header1();
             $header->job_title = Input::get('headerJobTitle');
             $header->template_id = $template->id;
             if (Input::has('headerResumeTitle')) {
                 $header->description = Input::get('headerResumeTitle');
             }
             if (Input::hasFile('headerImage')) {
                 $header->picture = Input::file('headerImage')->move("images/uploaded/");
             }
             if (Input::has('headerJobTitle')) {
                 $header->description = Input::get('headerJobTitle');
             }
             $header->save();
         }
         //Storing adjectives for template 2
         if (Input::has('adjectives1')) {
             $header1 = new Header1();
             $header1->template_id = $template->id;
             $header1->adjective = Input::get('adjectives1');
             $header1->save();
         }
         if (Input::has('adjectives2')) {
             $header2 = new Header1();
             $header2->template_id = $template->id;
             $header2->adjective = Input::get('adjectives2');
             $header2->save();
         }
         if (Input::has('adjectives3')) {
             $header3 = new Header1();
             $header3->template_id = $template->id;
             $header3->adjective = Input::get('adjectives3');
             $header3->save();
         }
         //Checking for up to 6 skill inputs to be accpeted
         if (Input::has('skillPercent1') && Input::has('skillTitle1')) {
             $skill1 = new Skill();
             $skill1->template_id = $template->id;
             $skill1->percent = Input::get('skillPercent1');
             $skill1->skill_title = Input::get('skillTitle1');
             if (Input::has('skillDescription1')) {
                 $skill1->description = Input::get('skillDescription1');
             }
             if (Input::has('skillDescriptionTitle1')) {
                 $skill1->description_title = Input::get('skillDescriptionTitle1');
             }
             if (Input::has('hobbies1')) {
                 $skill1->description_title = Input::get('hobbies1');
             }
             $skill1->save();
         }
         if (Input::has('skillPercent2') && Input::has('skillTitle2')) {
             $skill2 = new Skill();
             $skill2->template_id = $template->id;
             $skill2->percent = Input::get('skillPercent2');
             $skill2->skill_title = Input::get('skillTitle2');
             if (Input::has('skillDescription2')) {
                 $skill2->description = Input::get('skillDescription2');
             }
             if (Input::has('skillDescriptionTitle2')) {
                 $skill2->description_title = Input::get('skillDescriptionTitle2');
             }
             if (Input::has('hobbies2')) {
                 $skill2->description_title = Input::get('hobbies2');
             }
             $skill2->save();
         }
         if (Input::has('skillPercent3') && Input::has('skillTitle3')) {
             $skill3 = new Skill();
             $skill3->template_id = $template->id;
             $skill3->percent = Input::get('skillPercent3');
             $skill3->skill_title = Input::get('skillTitle3');
             if (Input::has('skillDescription3')) {
                 $skill3->description = Input::get('skillDescription3');
             }
             if (Input::has('skillDescriptionTitle3')) {
                 $skill3->description_title = Input::get('skillDescriptionTitle3');
             }
             if (Input::has('hobbies3')) {
                 $skill3->description_title = Input::get('hobbies3');
             }
             $skill3->save();
         }
         if (Input::has('skillPercent4') && Input::has('skillTitle4')) {
             $skill4 = new Skill();
             $skill4->template_id = $template->id;
             $skill4->percent = Input::get('skillPercent4');
             $skill4->skill_title = Input::get('skillTitle4');
             if (Input::has('skillDescription4') && Input::has('descriptionTitle4')) {
                 $skill4->description = Input::get('skillDescription4');
             }
             if (Input::has('skillDescriptionTitle4')) {
                 $skill4->description_title = Input::get('skillDescriptionTitle4');
             }
             $skill4->save();
         }
         if (Input::has('skillPercent5') && Input::has('skillTitle5')) {
             $skill5 = new Skill();
             $skill5->template_id = $template->id;
             $skill5->percent = Input::get('skillPercent5');
             $skill5->skill_title = Input::get('skillTitle5');
             if (Input::has('skillDescription5')) {
                 $skill5->description = Input::get('skillDescription5');
             }
             if (Input::has('skillDescriptionTitle5')) {
                 $skill5->description_title = Input::get('skillDescriptionTitle5');
             }
             $skill5->save();
         }
         //Knowledge storage starts here for template 2
         if (Input::has('knowledge1') && Input::has('miscHead1') && Input::has('miscFoot1') && Input::has('miscPercent1')) {
             $knowledge1 = new Knowledge();
             $knowledge1->template_id = $template->id;
             $knowledge1->knowledge_item = Input::get('knowledge1');
             $knowledge1->sub_percent = Input::get('miscPercent1');
             $knowledge1->sub_head = Input::get('miscHead1');
             $knowledge1->sub_foot = Input::get('miscFoot1');
             if (Input::has('miscTitle1')) {
                 $knowledge1->sub_title = Input::get('miscTitle1');
             }
             $knowledge1->save();
         }
         if (Input::has('knowledge2') && Input::has('miscHead2') && Input::has('miscFoot2') && Input::has('miscPercent2')) {
             $knowledge2 = new Knowledge();
             $knowledge2->template_id = $template->id;
             $knowledge2->knowledge_item = Input::get('knowledge2');
             $knowledge2->sub_percent = Input::get('miscPercent2');
             $knowledge2->sub_head = Input::get('miscHead2');
             $knowledge2->sub_foot = Input::get('miscFoot2');
             $knowledge2->save();
         }
         if (Input::has('knowledge3') && Input::has('miscHead3') && Input::has('miscFoot3') && Input::has('miscPercent3')) {
             $knowledge3 = new Knowledge();
             $knowledge3->template_id = $template->id;
             $knowledge3->knowledge_item = Input::get('knowledge3');
             $knowledge3->sub_percent = Input::get('miscPercent3');
             $knowledge3->sub_head = Input::get('miscHead3');
             $knowledge3->sub_foot = Input::get('miscFoot3');
             $knowledge3->save();
         }
         if (Input::has('knowledge4') && Input::has('miscHead4') && Input::has('miscFoot4') && Input::has('miscPercent4')) {
             $knowledge4 = new Knowledge();
             $knowledge4->template_id = $template->id;
             $knowledge4->knowledge_item = Input::get('knowledge4');
             $knowledge4->sub_percent = Input::get('miscPercent4');
             $knowledge4->sub_head = Input::get('miscHead4');
             $knowledge4->sub_foot = Input::get('miscFoot4');
             $knowledge4->save();
         }
         if (Input::has('aboutDescription1')) {
             $abouts1 = new About();
             $abouts1->template_id = $template->id;
             $abouts1->description = Input::get('aboutDescription1');
             if (Input::has('aboutTitle')) {
                 $abouts1->title = Input::get('aboutTitle');
             }
             if (Input::hasFile('aboutBackgroundImage1')) {
                 $abouts1->picture = Input::file('aboutBackgroundImage1')->move("images/uploaded/");
             }
             $abouts1->save();
         }
         if (Input::has('aboutDescription2')) {
             $abouts2 = new About();
             $abouts2->template_id = $template->id;
             $abouts2->description = Input::get('aboutDescription2');
             if (Input::has('aboutTitle')) {
                 $abouts2->title = Input::get('aboutTitle');
             }
             if (Input::hasFile('aboutBackgroundImage2')) {
                 $abouts2->picture = Input::file('aboutBackgroundImage2')->move("images/uploaded/");
             }
             $abouts2->save();
         }
         if (Input::has('aboutDescription3')) {
             $abouts3 = new About();
             $abouts3->template_id = $template->id;
             $abouts3->description = Input::get('aboutDescription3');
             if (Input::has('aboutTitle')) {
                 $abouts3->title = Input::get('aboutTitle');
             }
             if (Input::hasFile('aboutBackgroundImage3')) {
                 $abouts3->picture = Input::file('aboutBackgroundImage3')->move("images/uploaded/");
             }
             $abouts3->save();
         }
         if (Input::has('contactDescription')) {
             $contacts = new Contact();
             $contacts->template_id = $template->id;
             $contacts->description = Input::get('contactDescription');
             $contacts->save();
         }
         //Storing services currently for template 2
         if (Input::has('serviceTitle1') || Input::has('serviceTitle2') || Input::has('serviceTitle3') || Input::has('serviceTitle4') || Input::has('serviceTitle5') || Input::has('serviceTitle6')) {
             if (Input::has('serviceTitle1') && Input::has('serviceDescription1')) {
                 $service1 = new Service();
                 $service1->template_id = $template->id;
                 $service1->title = Input::get('serviceTitle1');
                 $service1->description = Input::get('serviceDescription1');
                 $service1->save();
             }
             if (Input::has('serviceTitle2') && Input::has('serviceDescription2')) {
                 $service2 = new Service();
                 $service2->template_id = $template->id;
                 $service2->title = Input::get('serviceTitle2');
                 $service2->description = Input::get('serviceDescription2');
                 $service2->save();
             }
             if (Input::has('serviceTitle3') && Input::has('serviceDescription3')) {
                 $service3 = new Service();
                 $service3->template_id = $template->id;
                 $service3->title = Input::get('serviceTitle3');
                 $service3->description = Input::get('serviceDescription3');
                 $service3->save();
             }
             if (Input::has('serviceTitle4') && Input::has('serviceDescription4')) {
                 $service4 = new Service();
                 $service4->template_id = $template->id;
                 $service4->title = Input::get('serviceTitle4');
                 $service4->description = Input::get('serviceDescription4');
                 $service4->save();
             }
             if (Input::has('serviceTitle5') && Input::has('serviceDescription5')) {
                 $service5 = new Service();
                 $service5->template_id = $template->id;
                 $service5->title = Input::get('serviceTitle5');
                 $service5->description = Input::get('serviceDescription5');
                 $service5->save();
             }
             if (Input::has('serviceTitle6') && Input::has('serviceDescription6')) {
                 $service6 = new Service();
                 $service6->template_id = $template->id;
                 $service6->title = Input::get('serviceTitle6');
                 $service6->description = Input::get('serviceDescription6');
                 $service6->save();
             }
         }
         //There are the inputs for the portfolio storeTemplate1Images
         if (Input::has('portfolioDescription1')) {
             $portfolio1 = new Portfolio();
             if (Input::has('portfolioTitle1')) {
                 $portfolio1->title = Input::get('portfolioTitle1');
             }
             $portfolio1->template_id = $template->id;
             $portfolio1->description = Input::get('portfolioDescription1');
             if (Input::hasFile('portfolioPicture1')) {
                 $portfolio1->picture = Input::file('portfolioPicture1')->move("img/uploaded/");
             }
             if (Input::has('portfolioLink1')) {
                 $portfolio1->link = Input::get('portfolioLink1');
             }
             if (Input::has('portfolioCategory1')) {
                 $portfolio1->category = Input::get('portfolioCategory1');
             }
             $portfolio1->save();
         }
         if (Input::has('portfolioDescription2')) {
             $portfolio2 = new Portfolio();
             if (Input::has('portfolioTitle2')) {
                 $portfolio2->title = Input::get('portfolioTitle2');
             }
             $portfolio2->template_id = $template->id;
             $portfolio2->description = Input::get('portfolioDescription2');
             if (Input::hasFile('portfolioPicture2')) {
                 $portfolio2->picture = Input::file('portfolioPicture2')->move("img/uploaded/");
             }
             if (Input::has('portfolioLink2')) {
                 $portfolio2->link = Input::get('portfolioLink2');
             }
             if (Input::has('portfolioCategory2')) {
                 $portfolio2->category = Input::get('portfolioCategory2');
             }
             $portfolio2->save();
         }
         if (Input::has('portfolioDescription3')) {
             $portfolio3 = new Portfolio();
             if (Input::has('portfolioTitle3')) {
                 $portfolio3->title = Input::get('portfolioTitle3');
             }
             $portfolio3->template_id = $template->id;
             $portfolio3->description = Input::get('portfolioDescription3');
             if (Input::hasFile('portfolioPicture3')) {
                 $portfolio3->picture = Input::file('portfolioPicture3')->move("img/uploaded/");
             }
             if (Input::has('portfolioLink3')) {
                 $portfolio3->link = Input::get('portfolioLink3');
             }
             if (Input::has('portfolioCategory3')) {
                 $portfolio3->category = Input::get('portfolioCategory3');
             }
             $portfolio3->save();
         }
         if (Input::has('portfolioDescription4')) {
             $portfolio4 = new Portfolio();
             if (Input::has('portfolioTitle4')) {
                 $portfolio4->title = Input::get('portfolioTitle4');
             }
             $portfolio4->template_id = $template->id;
             $portfolio4->description = Input::get('portfolioDescription4');
             if (Input::hasFile('portfolioPicture4')) {
                 $portfolio4->picture = Input::file('portfolioPicture4')->move("img/uploaded/");
             }
             if (Input::has('portfolioLink4')) {
                 $portfolio4->link = Input::get('portfolioLink4');
             }
             if (Input::has('portfolioCategory4')) {
                 $portfolio4->category = Input::get('portfolioCategory4');
             }
             $portfolio4->save();
         }
         if (Input::has('portfolioDescription5')) {
             $portfolio5 = new Portfolio();
             if (Input::has('portfolioTitle5')) {
                 $portfolio5->title = Input::get('portfolioTitle5');
             }
             $portfolio5->template_id = $template->id;
             $portfolio5->description = Input::get('portfolioDescription5');
             if (Input::hasFile('portfolioPicture5')) {
                 $portfolio5->picture = Input::file('portfolioPicture5')->move("img/uploaded/");
             }
             if (Input::has('portfolioLink5')) {
                 $portfolio5->link = Input::get('portfolioLink5');
             }
             if (Input::has('portfolioCategory5')) {
                 $portfolio5->category = Input::get('portfolioCategory5');
             }
             $portfolio5->save();
         }
         if (Input::has('portfolioDescription6')) {
             $portfolio6 = new Portfolio();
             if (Input::has('portfolioTitle6')) {
                 $portfolio6->title = Input::get('portfolioTitle6');
             }
             $portfolio6->template_id = $template->id;
             $portfolio6->description = Input::get('portfolioDescription6');
             if (Input::hasFile('portfolioPicture6')) {
                 $portfolio6->picture = Input::file('portfolioPicture6')->move("img/uploaded/");
             }
             if (Input::hasFile('portfolioLink6')) {
                 $portfolio6->link = Input::get('portfolioLink6');
             }
             if (Input::hasFile('portfolioCategory6')) {
                 $portfolio6->category = Input::get('portfolioCategory6');
             }
             $portfolio6->save();
         }
         //Awards
         if (Input::has('awardTitle1') && Input::has('awardNumber1')) {
             $award1 = new Award();
             $award1->template_id = $template->id;
             $award1->award_number = Input::get('awardTitle1');
             $award1->award_title = Input::get('awardNumber1');
             $award1->save();
         }
         if (Input::has('awardTitle2') && Input::has('awardNumber2')) {
             $award2 = new Award();
             $award2->template_id = $template->id;
             $award2->award_number = Input::get('awardTitle2');
             $award2->award_title = Input::get('awardNumber2');
             $award2->save();
         }
         if (Input::has('awardTitle3') && Input::has('awardNumber3')) {
             $award3 = new Award();
             $award3->template_id = $template->id;
             $award3->award_number = Input::get('awardTitle3');
             $award3->award_title = Input::get('awardNumber3');
             $award3->save();
         }
         //Storing up to 6 work experience sections
         if (Input::has('workExperienceStart1') && Input::has('workExperienceDescription1') && Input::has('workExperienceTitle1')) {
             $experience1 = new workExperience();
             if (Input::has('workExperienceExtraText1')) {
                 $experience1->description = Input::get('workExperienceExtraText1');
             }
             $experience1->template_id = $template->id;
             $experience1->start_date = Input::get('workExperienceStart1');
             $experience1->title = Input::get('workExperienceTitle1');
             $experience1->description = Input::get('workExperienceDescription1');
             if (Input::has('workExperienceEnd1')) {
                 $experience1->end_date = Input::get('workExperienceEnd1');
             }
             $experience1->save();
         }
         if (Input::has('workExperienceStart2') && Input::has('workExperienceDescription2') && Input::has('workExperienceTitle2')) {
             $experience2 = new workExperience();
             $experience2->template_id = $template->id;
             $experience2->start_date = Input::get('workExperienceStart2');
             $experience2->title = Input::get('workExperienceTitle2');
             $experience2->description = Input::get('workExperienceDescription2');
             if (Input::has('workExperienceEnd2')) {
                 $experience2->end_date = Input::get('workExperienceEnd2');
             }
             $experience2->save();
         }
         if (Input::has('workExperienceStart3') && Input::has('workExperienceDescription3') && Input::has('workExperienceTitle3')) {
             $experience3 = new workExperience();
             $experience3->template_id = $template->id;
             $experience3->start_date = Input::get('workExperienceStart3');
             $experience3->title = Input::get('workExperienceTitle3');
             $experience3->description = Input::get('workExperienceDescription3');
             if (Input::has('workExperienceEnd3')) {
                 $experience3->end_date = Input::get('workExperienceEnd3');
             }
             $experience3->save();
         }
         if (Input::has('workExperienceStart4') && Input::has('workExperienceDescription4') && Input::has('workExperienceTitle4')) {
             $experience4 = new workExperience();
             $experience4->template_id = $template->id;
             $experience4->start_date = Input::get('workExperienceStart4');
             $experience4->title = Input::get('workExperienceTitle4');
             $experience4->description = Input::get('workExperienceDescription4');
             if (Input::has('workExperienceEnd4')) {
                 $experience4->end_date = Input::get('workExperienceEnd4');
             }
             $experience4->save();
         }
         if (Input::has('workExperienceStart5') && Input::has('workExperienceDescription5') && Input::has('workExperienceTitle5')) {
             $experience5 = new workExperience();
             $experience5->template_id = $template->id;
             $experience5->start_date = Input::get('workExperienceStart5');
             $experience5->title = Input::get('workExperienceTitle5');
             $experience5->description = Input::get('workExperienceDescription5');
             if (Input::has('workExperienceEnd5')) {
                 $experience5->end_date = Input::get('workExperienceEnd5');
             }
             $experience5->save();
         }
         if (Input::has('workExperienceStart6') && Input::has('workExperienceDescription6') && Input::has('workExperienceTitle6')) {
             $experience6 = new workExperience();
             $experience6->template_id = $template->id;
             $experience6->start_date = Input::get('workExperienceStart6');
             $experience6->title = Input::get('workExperienceTitle6');
             $experience6->description = Input::get('workExperienceDescription6');
             if (Input::has('workExperienceEnd6')) {
                 $experience6->end_date = Input::get('workExperienceEnd6');
             }
             $experience6->save();
         }
         if (Input::has('educationStart1') && Input::has('educationDescription1') && Input::has('educationTitle1')) {
             $education1 = new Education();
             $education1->template_id = $template->id;
             $education1->start_date = Input::get('educationStart1');
             if (Input::has('educationEnd1')) {
                 $education1->end_date = Input::get('educationEnd1');
             }
             $education1->title = Input::get('educationTitle1');
             $education1->description = Input::get('educationDescription1');
             $education1->save();
         }
         if (Input::has('educationStart2') && Input::has('educationDescription2') && Input::has('educationTitle2')) {
             $education2 = new Education();
             $education2->template_id = $template->id;
             $education2->start_date = Input::get('educationStart2');
             if (Input::has('educationEnd2')) {
                 $education2->end_date = Input::get('educationEnd2');
             }
             $education2->title = Input::get('educationTitle2');
             $education2->description = Input::get('educationDescription2');
             $education2->save();
         }
         if (Input::has('educationStart3') && Input::has('educationDescription3') && Input::has('educationTitle3')) {
             $education3 = new Education();
             $education3->template_id = $template->id;
             $education3->start_date = Input::get('educationStart3');
             if (Input::has('educationEnd3')) {
                 $education3->end_date = Input::get('educationEnd3');
             }
             $education3->title = Input::get('educationTitle3');
             $education3->description = Input::get('educationDescription3');
             $education3->save();
         }
         if (Input::has('educationStart4') && Input::has('educationDescription4') && Input::has('educationTitle4')) {
             $education4 = new Education();
             $education4->template_id = $template->id;
             $education4->start_date = Input::get('educationStart4');
             if (Input::has('educationEnd4')) {
                 $education4->end_date = Input::get('educationEnd4');
             }
             $education4->title = Input::get('educationTitle4');
             $education4->description = Input::get('educationDescription4');
             $education4->save();
         }
     }
     return Redirect::action('UsersController@getProfile');
 }