Exemplo n.º 1
0
 protected static function createPage($name, $parent = false, $type = false, $template = false)
 {
     if ($parent === false) {
         $parent = Page::getByID(HOME_CID);
     } else {
         if (is_string($parent)) {
             $parent = Page::getByPath($parent);
         }
     }
     if ($type === false) {
         $type = 1;
     }
     if (is_string($type)) {
         $pt = PageType::getByHandle($type);
     } else {
         $pt = PageType::getByID($type);
     }
     if ($template === false) {
         $template = 1;
     }
     if (is_string($template)) {
         $template = PageTemplate::getByHandle($template);
     } else {
         $template = PageTemplate::getByID($template);
     }
     $page = $parent->add($pt, array('cName' => $name, 'pTemplateID' => $template->getPageTemplateID()));
     return $page;
 }
<?php

defined('C5_EXECUTE') or die("Access Denied.");
if (!ini_get('safe_mode')) {
    @set_time_limit(0);
}
/* @var $text Concrete5_Helper_Text */
$text = \Loader::helper('text');
$bID = isset($_POST['bID']) ? $_POST['bID'] : '';
$block = \Block::getByID($bID);
$controller = $block->getInstance();
$parentPage = $block->getBlockCollectionObject();
$pageType = \PageType::getByHandle('worldskills_skill');
$template = \PageTemplate::getByHandle('full');
$skills = $controller->getSkills();
foreach ($skills['skills'] as $skill) {
    $skillId = $skill['id'];
    $name = $skill['name']['text'];
    $slug = $text->urlify($name);
    $page = null;
    // try to load existing page
    $pageList = new PageList();
    $pageList->filterByParentID($parentPage->getCollectionId());
    $pageList->filterByAttribute('worldskills_skill_id', $skillId);
    $pages = $pageList->get(1);
    if (is_array($pages) && isset($pages[0])) {
        $page = $pages[0];
    }
    if (!$page) {
        // create page
        $data = array('cName' => $name, 'cDescription' => '', 'cHandle' => $slug);
Exemplo n.º 3
0
    public function install()
    {
        $pkg = parent::install();
        // Dashboard Page
        $sp = SinglePage::add('/dashboard/forums', $pkg);
        if (is_object($sp)) {
            $sp->update(array('cName' => t('Forums'), 'cDescription' => t('Forums Dashboard')));
        }
        // Add Sidebar block set
        BlockTypeSet::add('forums', 'Forums', $pkg);
        // Add forum moderator user group
        $forumGroup = Group::getByName('Forum Moderators');
        if (!is_object($authorGroup)) {
            Group::add('Forum Moderators', t('Forum Moderators, delete, edit, approve'));
        }
        // install blocks
        BlockType::installBlockTypeFromPackage('webli_forum_post', $pkg);
        BlockType::installBlockTypeFromPackage('webli_forum_list', $pkg);
        BlockType::installBlockTypeFromPackage('webli_forum_search', $pkg);
        BlockType::installBlockTypeFromPackage('webli_forum_archive', $pkg);
        BlockType::installBlockTypeFromPackage('webli_forum_tags', $pkg);
        // Add Collection Attribute Set
        $akCat = AttributeKeyCategory::getByHandle('collection');
        $akCat->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
        $akCatSet = $akCat->addSet('forums', t('Forums'), $pkg);
        // Add Collection Attributes
        $attribute = CollectionAttributeKey::getByHandle('forum_post');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('textarea');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_post', 'akName' => t('Forum Post'), 'akIsSearchableIndexed' => true, 'akTextareaDisplayMode' => 'rich_text'), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_category');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('boolean');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_category', 'akName' => t('Forum Category')), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_email');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('text');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_email', 'akName' => t('Forum Email Address'), 'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_name');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('text');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_name', 'akName' => t('Forum Name'), 'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_pin');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('boolean');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_pin', 'akName' => t('Pin Forum Post')), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_post_approved');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('boolean');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_post_approved', 'akName' => t('Forum Post Approved')), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('tags');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('select');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'tags', 'akName' => t('Tags'), 'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($akCatSet);
        }
        $attribute = CollectionAttributeKey::getByHandle('forum_image');
        if (!is_object($attribute)) {
            $att = AttributeType::getByHandle('image_file');
            // add to attribute set
            CollectionAttributeKey::add($att, array('akHandle' => 'forum_image', 'akName' => t('Forum Image')), $pkg)->setAttributeSet($akCatSet);
            $addAttribute = CollectionAttributeKey::getByHandle('forum_image');
        }
        // Add top level Forums Page
        $forumPage = \Page::getByPath('/forums');
        if (!is_object($forumPage) || $forumPage->cID == null) {
            $parentPage = \Page::getByID(1);
            $pageType = \PageType::getByHandle('right_sidebar');
            $template = \PageTemplate::getByHandle('right_sidebar');
            $forumsPage = $parentPage->add($pageType, array('cName' => t('Forums'), 'cDescription' => t('Top Level Forums Page'), 'cHandle ' => 'forums'), $template);
            //Add forum_category page attribute
            $forumsPage->setAttribute('forum_category', 1);
        }
        // Add top Forum Search Results Page
        $forumSearchPage = \Page::getByPath('/forum-search');
        if (!is_object($forumSearchPage) || $forumSearch->cID == null) {
            $parentPage = \Page::getByID(1);
            $pageType = \PageType::getByHandle('right_sidebar');
            $template = \PageTemplate::getByHandle('right_sidebar');
            $forumSearchPage = $parentPage->add($pageType, array('cName' => t('Forum Search'), 'cDescription' => t('Forum Search Page'), 'cHandle ' => 'forum-search'), $template);
            $forumSearchPage->setAttribute('exclude_nav', 1);
        }
        // Add Forum Post Page Template
        if (!is_object(PageTemplate::getByHandle('forum_post'))) {
            $pageTemplate = PageTemplate::add('forum_post', 'Forum Post', 'landing.png', $pkg);
        }
        // Add Forum Post Page Type
        if (!is_object(PageType::getByHandle('forum_post'))) {
            $data = array('handle' => 'forum_post', 'name' => 'Forum Post', 'ptLaunchInComposer' => true, 'ptIsFrequentlyAdded' => true, 'defaultTemplate' => PageTemplate::getByHandle('forum_post'), 'allowedTemplates' => 'C', 'templates' => array(PageTemplate::getByHandle('forum_post')));
            $pt = PageType::add($data, $pkg);
        }
        /* Get blog_post page template */
        $pageType = \PageType::getByHandle('forum_post');
        $ctTemplate = $pageType->getPageTypeDefaultPageTemplateObject();
        $forumPostTemplate = $pageType->getPageTypePageTemplateDefaultPageObject($ctTemplate);
        /* Add Composer Layouts */
        $basics = $pageType->addPageTypeComposerFormLayoutSet('Basics', 'Basic Info');
        $post = $pageType->addPageTypeComposerFormLayoutSet('Forum Post', 'Forum Post');
        /* Add Built in Properties */
        $cct = ComposerControlType::getByHandle('core_page_property');
        /* Post Title */
        $control = $cct->getPageTypeComposerControlByIdentifier('name');
        $control->addToPageTypeComposerFormLayoutSet($basics);
        /* Post Slug */
        $control = $cct->getPageTypeComposerControlByIdentifier('url_slug');
        $control->addToPageTypeComposerFormLayoutSet($basics);
        /* Post Publish Location */
        $control = $cct->getPageTypeComposerControlByIdentifier('publish_target');
        $control->addToPageTypeComposerFormLayoutSet($basics);
        /* Post Date */
        $control = $cct->getPageTypeComposerControlByIdentifier('date_time');
        $control->addToPageTypeComposerFormLayoutSet($basics);
        /* Post Author */
        $control = $cct->getPageTypeComposerControlByIdentifier('user');
        $control->addToPageTypeComposerFormLayoutSet($basics);
        /* Add Attributes */
        $cct = ComposerControlType::getByHandle('collection_attribute');
        /* Forum Pin */
        $attributeId = CollectionAttributeKey::getByHandle('forum_pin')->getAttributeKeyID();
        $control = $cct->getPageTypeComposerControlByIdentifier($attributeId);
        $control->addToPageTypeComposerFormLayoutSet($post);
        /* Forum Post Approved */
        $attributeId = CollectionAttributeKey::getByHandle('forum_post_approved')->getAttributeKeyID();
        $control = $cct->getPageTypeComposerControlByIdentifier($attributeId);
        $control->addToPageTypeComposerFormLayoutSet($post);
        /* Forum Post */
        $attributeId = CollectionAttributeKey::getByHandle('forum_post')->getAttributeKeyID();
        $control = $cct->getPageTypeComposerControlByIdentifier($attributeId);
        $control->addToPageTypeComposerFormLayoutSet($post);
        /* Forum Image */
        $attributeId = CollectionAttributeKey::getByHandle('forum_image')->getAttributeKeyID();
        $control = $cct->getPageTypeComposerControlByIdentifier($attributeId);
        $control->addToPageTypeComposerFormLayoutSet($post);
        /* Forum Tags */
        $attributeId = CollectionAttributeKey::getByHandle('tags')->getAttributeKeyID();
        $control = $cct->getPageTypeComposerControlByIdentifier($attributeId);
        $control->addToPageTypeComposerFormLayoutSet($post);
        /* Add default Blocks to page template */
        $ctTemplate = $pageType->getPageTypeDefaultPageTemplateObject();
        $forumPostTemplate = $pageType->getPageTypePageTemplateDefaultPageObject($ctTemplate);
        //Add exclude_nav page attributeto Forum Post Template
        $forumPostTemplate->setAttribute('exclude_nav', 1);
        // Get Forum Category Page
        $forumCategoryPage = Page::getByPath('/forums');
        //Add forum_category page attribute
        $forumCategoryPage->setAttribute('forum_category', 1);
        // Get Forum Search Page
        $forumSearchPage = Page::getByPath('/forum-search');
        //Add exclude_nav page attribute
        $forumSearchPage->setAttribute('exclude_nav', 1);
        // Install Blocks
        //install Forum Post Block
        $forumPost = BlockType::getByHandle('webli_forum_post');
        $forumPostData = array();
        $forumCategoryPage->addBlock($forumPost, 'Main', $forumPostData);
        //install forum post block to forum_post template
        $forumPostTemplate->addBlock($forumPost, 'Forum Post', $forumPostData);
        //install Forum List Block on Forums top level page
        $forumList = BlockType::getByHandle('webli_forum_list');
        $forumListData = array();
        $forumListData['num'] = 25;
        $forumListData['paginate'] = 1;
        $forumListData['cParentID'] = $forumCategoryPage->getCollectionID();
        $forumListData['orderBy'] = 'chrono_desc';
        $forumListData['use_content'] = 1;
        $forumListData['truncateSummaries'] = 1;
        $forumListData['truncateChars'] = 200;
        $forumListData['display_author'] = 1;
        $forumListData['includeDate'] = 1;
        $forumListData['includeName'] = 1;
        $forumListData['includeDescription'] = 1;
        $forumListData['date_format'] = 'l F j, Y g:ia';
        $forumListData['forum_pin'] = 1;
        $forumListData['forumReplies'] = 3;
        $forumListData['thumb_width'] = 250;
        $forumListData['thumb_height'] = 150;
        $forumListData['crop'] = 1;
        $forumListData['noResultsMessage'] = 'No Forum Posts available to view.';
        $forumCategoryPage->addBlock($forumList, 'Main', $forumListData);
        // Install Forum Search Block on forum_post Page template
        $forumSearch = BlockType::getByHandle('webli_forum_search');
        $forumSearchData = array();
        $forumSearchData['title'] = 'Forum Search';
        $forumSearchData['postTo_cID'] = $forumSearchPage->getCollectionID();
        $forumSearchData['baseSearchPath'] = 'PARENT';
        $forumPostTemplate->addBlock($forumSearch, 'Sidebar', $forumSearchData);
        //install Forum Search Block Forums forum_category Page
        $forumSearchData = array();
        $forumSearchData['title'] = 'Forum Search';
        $forumSearchData['postTo_cID'] = $forumSearchPage->getCollectionID();
        $forumSearchData['baseSearchPath'] = $forumCategoryPage->getCollectionPath();
        $forumCategoryPage->addBlock($forumSearch, 'Sidebar', $forumSearchData);
        //install Forum Search Block on Forum Search Page
        $forumSearchData = array();
        $forumSearchData['title'] = 'Forum Search';
        $forumSearchData['buttonText'] = 'Search';
        $forumSearchData['baseSearchPath'] = $forumCategoryPage->getCollectionPath();
        $forumSearchPage->addBlock($forumSearch, 'Main', $forumSearchData);
        //install Forum Archive Block on forum_post template
        $forumArchive = BlockType::getByHandle('webli_forum_archive');
        $forumArchiveData = array();
        $forumArchiveData['title'] = 'Forum Archive';
        $forumArchiveData['cParentID'] = 'PARENT';
        $forumPostTemplate->addBlock($forumArchive, 'Sidebar', $forumArchiveData);
        //install Forum Archive Block
        $forumArchiveData = array();
        $forumArchiveData['title'] = 'Forum Archive';
        $forumArchiveData['cParentID'] = $forumCategoryPage->getCollectionID();
        $forumCategoryPage->addBlock($forumArchive, 'Sidebar', $forumArchiveData);
        $forumSearchPage->addBlock($forumArchive, 'Sidebar', $forumArchiveData);
        //install Forum Tags Block on forum_post template
        $forumTags = BlockType::getByHandle('webli_forum_tags');
        $forumTagsData = array();
        $forumTagsData['title'] = 'Forum Tags';
        $forumTagsData['cParentID'] = 'PARENT';
        $forumTagsData['postTo_cID'] = $forumSearchPage->getCollectionID();
        $forumTagsData['baseSearchPath'] = $forumCategoryPage->getCollectionPath();
        $forumTagsData['min_height'] = 15;
        $forumTagsData['max_height'] = 30;
        $forumPostTemplate->addBlock($forumTags, 'Sidebar', $forumTagsData);
        //install Forum Tags Block
        $forumTagsData = array();
        $forumTagsData['title'] = 'Forum Tags';
        $forumTagsData['cParentID'] = $forumCategoryPage->getCollectionID();
        $forumTagsData['postTo_cID'] = $forumSearchPage->getCollectionID();
        $forumTagsData['baseSearchPath'] = $forumCategoryPage->getCollectionPath();
        $forumTagsData['min_height'] = 15;
        $forumTagsData['max_height'] = 30;
        $forumCategoryPage->addBlock($forumTags, 'Sidebar', $forumTagsData);
        $forumSearchPage->addBlock($forumTags, 'Sidebar', $forumTagsData);
        //install Conversations block to forum_post template
        $conversations = BlockType::getByHandle('core_conversation');
        $conversationsData = array();
        $conversationsData['attachmentsEnabled'] = 0;
        $conversationsData['addMessageLabel'] = t('Add a Comment');
        $conversationsData['itemsPerPage'] = 25;
        $conversationsData['enablePosting'] = 1;
        $conversationsData['enableCommentRating'] = 1;
        $conversationsData['paginate'] = 1;
        $conversationsData['displayMode'] = 'threaded';
        $conversationsData['displayPostingForm'] = 'bottom';
        $forumPostTemplate->addBlock($conversations, 'Forum Replies', $conversationsData);
        $db = Loader::db();
        // insert default page category values
        $db->Execute('insert into btWebliForums (
				cID,
				display_title,
				display_author,
				display_date,
				date_format,
				display_tags,
				enable_comments,
				enable_breadcrumb,
				crop_image,
				display_image,
				image_height,
				image_width,
				display_avatars,
				forum_search_block,
				forum_archive_block,
				forum_tags_block,
				rich_text,
				page_template,
				page_type
				) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(0, 1, 1, 1, 'l F j, Y g:ia', 1, 1, 1, 0, 1, 350, 250, 1, 1, 1, 1, 1, $pageTemplate->getPageTemplateID(), $pageType->getPageTypeID()));
        // Add Sample Forum Post
        $forumsPage = \Page::getByPath('/forums');
        if (is_object($forumsPage) || $forumsPage->cID != null) {
            $pageType = \PageType::getByHandle('forum_post');
            $template = \PageTemplate::getByHandle('forum_post');
            $samplePost = $forumsPage->add($pageType, array('cName' => 'My First Forum Post', 'cDescription' => 'First Forum Post', 'cHandle ' => 'first-forum-post'), $template);
            $samplePost->setAttribute('forum_post', t('
				<p>Hey, Congratulations, you have installed Forums for Concrete5.  Forums will give visitors to your site frontend
				editing capabilities to add Forum Messages and reply to existing messages.</p>
				<p>Administrators have access to the Forums Dashboard Page to customize and manage your forums.</p>
				<p>So get your forum started and if you have any comments or questions visit <a href="http://forums.webli.us" target="_blank">forums.webli.us</a></p>'));
            $samplePost->setAttribute('forum_post_approved', 1);
            $samplePost->setAttribute('tags', array('Forums', t('Frist Message')));
        }
        $cms = Core::make('app');
        $cms->clearCaches();
    }
 public function view($pagetypehandle = '', $success = 0)
 {
     $homepage = Page::getByID(HOME_CID);
     $emptysite = $homepage->getFirstChild('cDisplayOrder asc', true) === false;
     $this->set('emptysite', $emptysite);
     $typeList = PageType::getList();
     $pageTypesSelect = array();
     foreach ($typeList as $_pagetype) {
         $pageTypesSelect[$_pagetype->getPageTypeHandle()] = $_pagetype;
     }
     $this->set('pageTypes', $pageTypesSelect);
     $onepagetype = count($pageTypesSelect) == 1;
     $this->set('onepagetype', $onepagetype);
     if ($pagetypehandle) {
         $pageType = \PageType::getByHandle($pagetypehandle);
         if ($pageType) {
             $pageTemplates = $pageType->getPageTypePageTemplateObjects();
             $pageTemplatesSelect = array();
             foreach ($pageTemplates as $pt) {
                 $pageTemplatesSelect[$pt->getPageTemplateID()] = $pt->getPageTemplateDisplayName();
             }
             $this->set('pageTemplates', $pageTemplatesSelect);
             $this->set('pageType', $pageType);
         } else {
             $this->redirect('/dashboard/sitemap/add_multiple_pages/');
         }
         if ($success > 0) {
             $this->set('success', $success . ' ' . ($success > 1 ? t('pages created') : t('page created')));
         }
     } else {
         if ($onepagetype) {
             $this->redirect('/dashboard/sitemap/add_multiple_pages/' . array_pop($pageTypesSelect)->getPageTypeHandle());
         }
     }
     if ($this->post()) {
         $error = false;
         if ($this->post('parent_page') <= 0) {
             $this->error->add(t('A parent page must be selected'));
             $error = true;
         }
         if ($this->post('page_template') <= 0) {
             $this->error->add(t('A page template must be selected'));
             $error = true;
         }
         $pagenames = trim($this->post('pagenames'));
         if (!$pagenames) {
             $this->error->add(t('At least one page name must be entered'));
             $error = true;
         }
         if (substr($pagenames, 0, 1) == '-') {
             $this->error->add(t('The first page must not start with a dash'));
             $error = true;
         }
         if (!$error && $pagetypehandle) {
             $numpages = 0;
             $pagenames = explode("\n", trim($this->post('pagenames')));
             $parentPage = \Page::getByID($this->post('parent_page'));
             $parentList = array($parentPage);
             $currentLevel = 0;
             $pageTemplate = \PageTemplate::getByID($this->post('page_template'));
             if (is_object($parentPage) && is_object($pageType) && is_object($pageTemplate)) {
                 foreach ($pagenames as $pagename) {
                     $pagename = trim($pagename);
                     preg_match('/^(-\\s*)*/', $pagename, $matches);
                     if (!empty($matches)) {
                         $depth = strlen(str_replace(' ', '', $matches[0]));
                         $pagename = ltrim($pagename, '- ');
                         $pagename = trim($pagename);
                         if ($depth > $currentLevel && isset($parentList[1])) {
                             $currentLevel++;
                         }
                         if ($depth < $currentLevel) {
                             $currentLevel = $depth;
                         }
                     } else {
                         $currentLevel = 0;
                     }
                     $entry = $parentList[$currentLevel]->add($pageType, array('cName' => $pagename), $pageTemplate);
                     $parentList[$currentLevel + 1] = $entry;
                     $pageType->savePageTypeComposerForm($entry);
                     $entry->updateCollectionName($pagename);
                     $numpages++;
                 }
             }
             $this->redirect('/dashboard/sitemap/add_multiple_pages/' . $pagetypehandle . '/' . $numpages);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Users submits the completed survey.
  *
  * @param int $bID
  */
 public function action_submit_form($bID = false)
 {
     if ($this->bID != $bID) {
         return false;
     }
     $ip = Core::make('helper/validation/ip');
     $this->view();
     if ($ip->isBanned()) {
         $this->set('invalidIP', $ip->getErrorMessage());
         return;
     }
     $txt = Core::make('helper/text');
     $db = Database::connection();
     //question set id
     $qsID = intval($_POST['qsID']);
     if ($qsID == 0) {
         throw new Exception(t("Oops, something is wrong with the form you posted (it doesn't have a question set id)."));
     }
     //get all questions for this question set
     $rows = $db->GetArray("SELECT * FROM {$this->btQuestionsTablename} WHERE questionSetId=? AND bID=? order by position asc, msqID", array($qsID, intval($this->bID)));
     $errorDetails = array();
     // check captcha if activated
     if ($this->displayCaptcha) {
         $captcha = Core::make('helper/validation/captcha');
         if (!$captcha->check()) {
             $errors['captcha'] = t("Incorrect captcha code");
             $_REQUEST['ccmCaptchaCode'] = '';
         }
     }
     //checked required fields
     foreach ($rows as $row) {
         if ($row['inputType'] == 'datetime') {
             if (!isset($datetime)) {
                 $datetime = Core::make('helper/form/date_time');
             }
             $translated = $datetime->translate('Question' . $row['msqID']);
             if ($translated) {
                 $_POST['Question' . $row['msqID']] = $translated;
             }
         }
         if (intval($row['required']) == 1) {
             $notCompleted = 0;
             if ($row['inputType'] == 'email') {
                 if (!Core::make('helper/validation/strings')->email($_POST['Question' . $row['msqID']])) {
                     $errors['emails'] = t('You must enter a valid email address.');
                     $errorDetails[$row['msqID']]['emails'] = $errors['emails'];
                 }
             }
             if ($row['inputType'] == 'checkboxlist') {
                 $answerFound = 0;
                 foreach ($_POST as $key => $val) {
                     if (strstr($key, 'Question' . $row['msqID'] . '_') && strlen($val)) {
                         $answerFound = 1;
                     }
                 }
                 if (!$answerFound) {
                     $notCompleted = 1;
                 }
             } elseif ($row['inputType'] == 'fileupload') {
                 if (!isset($_FILES['Question' . $row['msqID']]) || !is_uploaded_file($_FILES['Question' . $row['msqID']]['tmp_name'])) {
                     $notCompleted = 1;
                 }
             } elseif (!strlen(trim($_POST['Question' . $row['msqID']]))) {
                 $notCompleted = 1;
             }
             if ($notCompleted) {
                 $errors['CompleteRequired'] = t("Complete required fields *");
                 $errorDetails[$row['msqID']]['CompleteRequired'] = $errors['CompleteRequired'];
             }
         }
     }
     //try importing the file if everything else went ok
     $tmpFileIds = array();
     if (!count($errors)) {
         foreach ($rows as $row) {
             if ($row['inputType'] != 'fileupload') {
                 continue;
             }
             $questionName = 'Question' . $row['msqID'];
             if (!intval($row['required']) && (!isset($_FILES[$questionName]['tmp_name']) || !is_uploaded_file($_FILES[$questionName]['tmp_name']))) {
                 continue;
             }
             $fi = new FileImporter();
             $resp = $fi->import($_FILES[$questionName]['tmp_name'], $_FILES[$questionName]['name']);
             if (!$resp instanceof Version) {
                 switch ($resp) {
                     case FileImporter::E_FILE_INVALID_EXTENSION:
                         $errors['fileupload'] = t('Invalid file extension.');
                         $errorDetails[$row['msqID']]['fileupload'] = $errors['fileupload'];
                         break;
                     case FileImporter::E_FILE_INVALID:
                         $errors['fileupload'] = t('Invalid file.');
                         $errorDetails[$row['msqID']]['fileupload'] = $errors['fileupload'];
                         break;
                 }
             } else {
                 $tmpFileIds[intval($row['msqID'])] = $resp->getFileID();
                 if (intval($this->addFilesToSet)) {
                     $fs = new FileSet();
                     $fs = $fs->getByID($this->addFilesToSet);
                     if ($fs->getFileSetID()) {
                         $fs->addFileToSet($resp);
                     }
                 }
             }
         }
     }
     if (count($errors)) {
         $this->set('formResponse', t('Please correct the following errors:'));
         $this->set('errors', $errors);
         $this->set('errorDetails', $errorDetails);
     } else {
         //no form errors
         //save main survey record
         $u = new User();
         $uID = 0;
         if ($u->isRegistered()) {
             $uID = $u->getUserID();
         }
         $q = "insert into {$this->btAnswerSetTablename} (questionSetId, uID) values (?,?)";
         $db->query($q, array($qsID, $uID));
         $answerSetID = $db->Insert_ID();
         $this->lastAnswerSetId = $answerSetID;
         $questionAnswerPairs = array();
         if (Config::get('concrete.email.form_block.address') && strstr(Config::get('concrete.email.form_block.address'), '@')) {
             $formFormEmailAddress = Config::get('concrete.email.form_block.address');
         } else {
             $adminUserInfo = UserInfo::getByID(USER_SUPER_ID);
             $formFormEmailAddress = $adminUserInfo->getUserEmail();
         }
         $replyToEmailAddress = $formFormEmailAddress;
         //loop through each question and get the answers
         foreach ($rows as $row) {
             //save each answer
             $answerDisplay = '';
             if ($row['inputType'] == 'checkboxlist') {
                 $answer = array();
                 $answerLong = "";
                 $keys = array_keys($_POST);
                 foreach ($keys as $key) {
                     if (strpos($key, 'Question' . $row['msqID'] . '_') === 0) {
                         $answer[] = $txt->sanitize($_POST[$key]);
                     }
                 }
             } elseif ($row['inputType'] == 'text') {
                 $answerLong = $txt->sanitize($_POST['Question' . $row['msqID']]);
                 $answer = '';
             } elseif ($row['inputType'] == 'fileupload') {
                 $answerLong = "";
                 $answer = intval($tmpFileIds[intval($row['msqID'])]);
                 if ($answer > 0) {
                     $answerDisplay = File::getByID($answer)->getVersion()->getDownloadURL();
                 } else {
                     $answerDisplay = t('No file specified');
                 }
             } elseif ($row['inputType'] == 'url') {
                 $answerLong = "";
                 $answer = $txt->sanitize($_POST['Question' . $row['msqID']]);
             } elseif ($row['inputType'] == 'email') {
                 $answerLong = "";
                 $answer = $txt->sanitize($_POST['Question' . $row['msqID']]);
                 if (!empty($row['options'])) {
                     $settings = unserialize($row['options']);
                     if (is_array($settings) && array_key_exists('send_notification_from', $settings) && $settings['send_notification_from'] == 1) {
                         $email = $txt->email($answer);
                         if (!empty($email)) {
                             $replyToEmailAddress = $email;
                         }
                     }
                 }
             } elseif ($row['inputType'] == 'telephone') {
                 $answerLong = "";
                 $answer = $txt->sanitize($_POST['Question' . $row['msqID']]);
             } else {
                 $answerLong = "";
                 $answer = $txt->sanitize($_POST['Question' . $row['msqID']]);
             }
             if (is_array($answer)) {
                 $answer = implode(',', $answer);
             }
             $questionAnswerPairs[$row['msqID']]['question'] = $row['question'];
             $questionAnswerPairs[$row['msqID']]['answer'] = $txt->sanitize($answer . $answerLong);
             $questionAnswerPairs[$row['msqID']]['answerDisplay'] = strlen($answerDisplay) ? $answerDisplay : $questionAnswerPairs[$row['msqID']]['answer'];
             $v = array($row['msqID'], $answerSetID, $answer, $answerLong);
             $q = "insert into {$this->btAnswersTablename} (msqID,asID,answer,answerLong) values (?,?,?,?)";
             $db->query($q, $v);
         }
         $foundSpam = false;
         $submittedData = '';
         foreach ($questionAnswerPairs as $questionAnswerPair) {
             $submittedData .= $questionAnswerPair['question'] . "\r\n" . $questionAnswerPair['answer'] . "\r\n" . "\r\n";
         }
         $antispam = Core::make('helper/validation/antispam');
         if (!$antispam->check($submittedData, 'form_block')) {
             // found to be spam. We remove it
             $foundSpam = true;
             $q = "delete from {$this->btAnswerSetTablename} where asID = ?";
             $v = array($this->lastAnswerSetId);
             $db->Execute($q, $v);
             $db->Execute("delete from {$this->btAnswersTablename} where asID = ?", array($this->lastAnswerSetId));
         }
         if (intval($this->notifyMeOnSubmission) > 0 && !$foundSpam) {
             if (Config::get('concrete.email.form_block.address') && strstr(Config::get('concrete.email.form_block.address'), '@')) {
                 $formFormEmailAddress = Config::get('concrete.email.form_block.address');
             } else {
                 $adminUserInfo = UserInfo::getByID(USER_SUPER_ID);
                 $formFormEmailAddress = $adminUserInfo->getUserEmail();
             }
             if ($this->questionSetId == 1454843347) {
                 $mh = Core::make('helper/mail');
                 $mh->to($this->recipientEmail);
                 $mh->from($formFormEmailAddress);
                 $mh->replyto($replyToEmailAddress);
                 $mh->addParameter('formName', $this->surveyName);
                 $mh->addParameter('questionSetId', $this->questionSetId);
                 $mh->addParameter('questionAnswerPairs', $questionAnswerPairs);
                 $mh->load('inscription');
                 $mh->setSubject('Une nouvelle inscription');
                 //echo $mh->body.'<br>';
                 @$mh->sendMail();
                 $mh2 = Core::make('helper/mail');
                 $mh2->from($formFormEmailAddress);
                 $mh2->addParameter('formName', $this->surveyName);
                 $mh2->addParameter('questionSetId', $this->questionSetId);
                 $mh2->addParameter('questionAnswerPairs', $questionAnswerPairs);
                 $mh2->load('inscription_public');
                 $mh2->setSubject('Votre inscription au dodgeball beach tournament 2016');
                 $mh2->to($_POST['Question6']);
                 @$mh2->sendMail();
                 $parentPage = Page::getbyID(158);
                 $pageType = \PageType::getByHandle('team');
                 $template = \PageTemplate::getByHandle('team');
                 $entry = $parentPage->add($pageType, array('cName' => $_POST['Question1'], 'cDescription' => $_POST['Question7']), $template);
                 /** @var \Concrete\Core\Page\Page $entry */
                 $entry->setAttribute('captain', $_POST['Question4']);
                 $entry->setAttribute('team_type', $_POST['Question3']);
                 $entry->setAttribute('team_slogan', $_POST['Question2']);
                 if (count($tmpFileIds) == 1) {
                     $obj_file = File::getById($tmpFileIds[8]);
                     $entry->setAttribute('team_image', $obj_file);
                 }
             } else {
                 $mh = Core::make('helper/mail');
                 $mh->to($this->recipientEmail);
                 $mh->from($formFormEmailAddress);
                 $mh->replyto($replyToEmailAddress);
                 $mh->addParameter('formName', $this->surveyName);
                 $mh->addParameter('questionSetId', $this->questionSetId);
                 $mh->addParameter('questionAnswerPairs', $questionAnswerPairs);
                 $mh->load('block_form_submission');
                 $mh->setSubject('Votre site dodgeball.ch');
                 //echo $mh->body.'<br>';
                 @$mh->sendMail();
             }
         }
         if (!$this->noSubmitFormRedirect) {
             if ($this->redirectCID > 0) {
                 $pg = Page::getByID($this->redirectCID);
                 if (is_object($pg) && $pg->cID) {
                     $this->redirect($pg->getCollectionPath());
                 }
             }
             $c = Page::getCurrentPage();
             header("Location: " . Core::make('helper/navigation')->getLinkToCollection($c, true) . "?surveySuccess=1&qsid=" . $this->questionSetId . "#formblock" . $this->bID);
             exit;
         }
     }
 }
<?php

defined('C5_EXECUTE') or die("Access Denied.");
if (!ini_get('safe_mode')) {
    @set_time_limit(0);
}
/* @var $text Concrete5_Helper_Text */
$text = \Loader::helper('text');
$bID = isset($_POST['bID']) ? $_POST['bID'] : '';
$block = \Block::getByID($bID);
$controller = $block->getInstance();
$parentPage = $block->getBlockCollectionObject();
$pageType = \PageType::getByHandle('worldskills_member');
$template = \PageTemplate::getByHandle('full');
$members = $controller->getMembers();
foreach ($members['members'] as $member) {
    $memberId = $member['id'];
    $name = $member['name']['text'];
    $slug = $text->urlify($name);
    $page = null;
    // try to load existing page
    $pageList = new PageList();
    $pageList->filterByParentID($parentPage->getCollectionId());
    $pageList->filterByAttribute('worldskills_member_id', $memberId);
    $pages = $pageList->get(1);
    if (is_array($pages) && isset($pages[0])) {
        $page = $pages[0];
    }
    if (!$page) {
        // create page
        $data = array('cName' => $name, 'cDescription' => '', 'cHandle' => $slug);
 public function configurePackage($pkg)
 {
     $theme = Theme::getByHandle('worldskills');
     if (!is_object($theme)) {
         $theme = Theme::add('worldskills', $pkg);
     }
     // add skill ID attribute
     $attributeKey = CollectionAttributeKey::getByHandle('worldskills_skill_id');
     if (!is_object($attributeKey)) {
         $type = AttributeType::getByHandle('text');
         $args = array('akHandle' => 'worldskills_skill_id', 'akName' => t('Skill ID'), 'akIsSearchable' => 1, 'akIsSearchableIndexed' => 1);
         CollectionAttributeKey::add($type, $args, $pkg);
     }
     // add skill page type
     $pageType = \PageType::getByHandle('worldskills_skill');
     if (!is_object($pageType)) {
         $template = \PageTemplate::getByHandle('full');
         \PageType::add(array('handle' => 'worldskills_skill', 'name' => 'Skill', 'defaultTemplate' => $template, 'allowedTemplates' => 'C', 'templates' => array($template), 'ptLaunchInComposer' => 0, 'ptIsFrequentlyAdded' => 0), $pkg)->setConfiguredPageTypePublishTargetObject(new PageTypePublishTargetAllConfiguration(PageTypePublishTargetAllType::getByHandle('all')));
     }
     // add member ID attribute
     $attributeKey = CollectionAttributeKey::getByHandle('worldskills_member_id');
     if (!is_object($attributeKey)) {
         $type = AttributeType::getByHandle('text');
         $args = array('akHandle' => 'worldskills_member_id', 'akName' => t('Member ID'), 'akIsSearchable' => 1, 'akIsSearchableIndexed' => 1);
         CollectionAttributeKey::add($type, $args, $pkg);
     }
     // add member page type
     $pageType = \PageType::getByHandle('worldskills_member');
     if (!is_object($pageType)) {
         $template = \PageTemplate::getByHandle('full');
         \PageType::add(array('handle' => 'worldskills_member', 'name' => 'Member', 'defaultTemplate' => $template, 'allowedTemplates' => 'C', 'templates' => array($template), 'ptLaunchInComposer' => 0, 'ptIsFrequentlyAdded' => 0), $pkg)->setConfiguredPageTypePublishTargetObject(new PageTypePublishTargetAllConfiguration(PageTypePublishTargetAllType::getByHandle('all')));
     }
     // add skill block
     $blockType = \BlockType::getByHandle('worldskills_skill');
     if (!is_object($blockType)) {
         \BlockType::installBlockTypeFromPackage('worldskills_skill', $pkg);
     }
     // add skill list block
     $blockType = \BlockType::getByHandle('worldskills_skill_list');
     if (!is_object($blockType)) {
         \BlockType::installBlockTypeFromPackage('worldskills_skill_list', $pkg);
     }
     // add people block
     $blockType = \BlockType::getByHandle('worldskills_people');
     if (!is_object($blockType)) {
         \BlockType::installBlockTypeFromPackage('worldskills_people', $pkg);
     }
     // add member block
     $blockType = \BlockType::getByHandle('worldskills_member');
     if (!is_object($blockType)) {
         \BlockType::installBlockTypeFromPackage('worldskills_member', $pkg);
     }
     // add member list block
     $blockType = \BlockType::getByHandle('worldskills_member_list');
     if (!is_object($blockType)) {
         \BlockType::installBlockTypeFromPackage('worldskills_member_list', $pkg);
     }
     try {
         $authenticationType = AuthenticationType::getByHandle('worldskills');
     } catch (\Exception $e) {
         $authenticationType = AuthenticationType::add('worldskills', 'WorldSkills Auth', 0, $pkg);
         $authenticationType->disable();
     }
     $page = \SinglePage::add('/dashboard/system/basics/worldskills', $pkg);
     if (is_object($pag)) {
         $page->updateCollectionName('WorldSkills');
     }
     \Config::save('worldskills.api_url', \Config::get('worldskills.api_url', 'https://api.worldskills.org'));
     \Config::save('worldskills.authorize_url', \Config::get('worldskills.authorize_url', 'https://auth.worldskills.org'));
 }