/**
  * Execute this command
  * @param array $arguments Array of commandline arguments
  */
 public function execute(array $arguments)
 {
     if (!$this->interface->yesNo('Removing workbench requires re-installing workbench to use it again. Are you sure?')) {
         return;
     }
     // Remove component from Db and FileSystem
     $component = new \Cx\Core\Core\Model\Entity\ReflectionComponent('Workbench', 'core_module');
     $component->remove();
     // Remove additional files (config, command line script)
     foreach ($this->interface->getWorkbench()->getFileList() as $file) {
         if (is_dir($file)) {
             \Cx\Lib\FileSystem\FileSystem::delete_folder(ASCMS_DOCUMENT_ROOT . $file, true);
         } else {
             \Cx\Lib\FileSystem\FileSystem::delete_file(ASCMS_DOCUMENT_ROOT . $file);
         }
     }
     $this->interface->show('Done');
 }
Exemple #2
0
 /**
  * Read NewsML documents
  *
  * Read the NewsML documents of the category with the id $categoryId from its data directory
  * and delete the documents after they are inserted into the database
  * @access public
  * @param integer $categoryId
  * @global object $objDatabase
  */
 function readDocuments($categoryId, $matchFilenamePattern = null)
 {
     global $objDatabase;
     $objDir = @opendir(ASCMS_DOCUMENT_ROOT . $this->arrCategories[$categoryId]['path']);
     if ($objDir) {
         $arrDocuments = array();
         $document = @readdir($objDir);
         while ($document) {
             if (!in_array($document, $this->_arrExcludeFiles) && strtolower(substr($document, -3)) == 'xml' && (!$matchFilenamePattern || preg_match($matchFilenamePattern, $document))) {
                 array_push($arrDocuments, $document);
             }
             $document = @readdir($objDir);
         }
         @closedir($objDir);
         \Cx\Lib\FileSystem\FileSystem::makeWritable(ASCMS_DOCUMENT_ROOT . $this->arrCategories[$categoryId]['path']);
         foreach ($arrDocuments as $document) {
             if ($this->_readDocument($categoryId, $document)) {
                 \Cx\Lib\FileSystem\FileSystem::makeWritable(ASCMS_DOCUMENT_ROOT . $this->arrCategories[$categoryId]['path'] . '/' . $document);
                 @copy(ASCMS_DOCUMENT_ROOT . $this->arrCategories[$categoryId]['path'] . '/' . $document, ASCMS_DOCUMENT_ROOT . '/si_online_archive/' . $document);
                 \Cx\Lib\FileSystem\FileSystem::makeWritable(ASCMS_DOCUMENT_ROOT . '/si_online_archive/' . $document);
                 \Cx\Lib\FileSystem\FileSystem::delete_file(ASCMS_DOCUMENT_ROOT . $this->arrCategories[$categoryId]['path'] . '/' . $document);
             }
         }
         //          print_r($this->_arrDocuments);
         foreach ($this->_arrDocuments as $dateId => $arrNewsItems) {
             foreach ($arrNewsItems as $newsItemId => $arrRevisions) {
                 krsort($arrRevisions, SORT_NUMERIC);
                 reset($arrRevisions);
                 $arrRevision = current($arrRevisions);
                 $revisionUpdateStatus = isset($arrRevision['revisionUpdateStatus']) ? $arrRevision['revisionUpdateStatus'] : '';
                 switch ($revisionUpdateStatus) {
                     case 'A':
                         $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_feed_newsml_documents WHERE providerId='" . $this->arrCategories[$categoryId]['providerId'] . "' AND dateId=" . $dateId . " AND newsItemId='" . $newsItemId . "'");
                         break;
                     default:
                         $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_feed_newsml_documents WHERE providerId='" . $this->arrCategories[$categoryId]['providerId'] . "' AND dateId=" . $dateId . " AND newsItemId='" . $newsItemId . "' AND revisionId != " . $arrRevision['revisionId']);
                         if (isset($arrRevision['dateId'])) {
                             $this->_addDocument($arrRevision['publicIdentifier'], $this->arrCategories[$categoryId]['providerId'], $dateId, $newsItemId, $arrRevision['revisionId'], $arrRevision['thisRevisionDate'], $arrRevision['urgency'], $arrRevision['subjectCode'], $arrRevision['headLine'], $arrRevision['dataContent'], $arrRevision['associatedNewsItems']);
                         }
                         break;
                 }
             }
         }
     }
 }
 /**
  * Save the event to the database
  *      
  * @param array $data
  * 
  * @return boolean true if saved successfully, false otherwise
  */
 function save($data)
 {
     global $objDatabase, $_LANGID, $_CONFIG, $objInit;
     parent::getSettings();
     if (empty($data['startDate']) || empty($data['endDate']) || empty($data['category']) || $data['seriesStatus'] == 1 && $data['seriesType'] == 2 && empty($data['seriesWeeklyDays'])) {
         return false;
     }
     foreach ($_POST['showIn'] as $key => $langId) {
         if (empty($_POST['title'][$langId]) && empty($_POST['title'][$_LANGID])) {
             return false;
         }
     }
     list($startDate, $strStartTime) = explode(' ', $data['startDate']);
     list($startHour, $startMin) = explode(':', $strStartTime);
     list($endDate, $strEndTime) = explode(' ', $data['endDate']);
     list($endHour, $endMin) = explode(':', $strEndTime);
     if ($data['all_day']) {
         list($startHour, $startMin) = array(0, 0);
         list($endHour, $endMin) = array(23, 59);
     }
     //event data
     $id = isset($data['copy']) && !empty($data['copy']) ? 0 : (isset($data['id']) ? intval($data['id']) : 0);
     $type = isset($data['type']) ? intval($data['type']) : 0;
     $startDate = date("Y-m-d H:i:s", parent::getDateTimestamp($startDate, intval($startHour), intval($startMin)));
     $endDate = date("Y-m-d H:i:s", parent::getDateTimestamp($endDate, intval($endHour), intval($endMin)));
     $google = isset($data['map'][$_LANGID]) ? intval($data['map'][$_LANGID]) : 0;
     $allDay = isset($data['all_day']) ? 1 : 0;
     $convertBBCode = $objInit->mode == 'frontend' && empty($id);
     $useCustomDateDisplay = isset($data['showDateSettings']) ? 1 : 0;
     $showStartDateList = isset($data['showStartDateList']) ? $data['showStartDateList'] : 0;
     $showEndDateList = isset($data['showEndDateList']) ? $data['showEndDateList'] : 0;
     if ($objInit->mode == 'backend') {
         // reset time values if "no time" is selected
         if ($data['showTimeTypeList'] == 0) {
             $showStartTimeList = 0;
             $showEndTimeList = 0;
         } else {
             $showStartTimeList = isset($data['showStartTimeList']) ? $data['showStartTimeList'] : '';
             $showEndTimeList = isset($data['showEndTimeList']) ? $data['showEndTimeList'] : '';
         }
         $showTimeTypeList = isset($data['showTimeTypeList']) ? $data['showTimeTypeList'] : '';
         $showStartDateDetail = isset($data['showStartDateDetail']) ? $data['showStartDateDetail'] : '';
         $showEndDateDetail = isset($data['showEndDateDetail']) ? $data['showEndDateDetail'] : '';
         // reset time values if "no time" is selected
         if ($data['showTimeTypeDetail'] == 0) {
             $showStartTimeDetail = 0;
             $showEndTimeDetail = 0;
         } else {
             $showStartTimeDetail = isset($data['showStartTimeDetail']) ? $data['showStartTimeDetail'] : '';
             $showEndTimeDetail = isset($data['showEndTimeDetail']) ? $data['showEndTimeDetail'] : '';
         }
         $showTimeTypeDetail = isset($data['showTimeTypeDetail']) ? $data['showTimeTypeDetail'] : '';
     } else {
         $showStartDateList = $this->arrSettings['showStartDateList'] == 1 ? 1 : 0;
         $showEndDateList = $this->arrSettings['showEndDateList'] == 1 ? 1 : 0;
         $showStartTimeList = $this->arrSettings['showStartTimeList'] == 1 ? 1 : 0;
         $showEndTimeList = $this->arrSettings['showEndTimeList'] == 1 ? 1 : 0;
         // reset time values if "no time" is selected
         if ($showStartTimeList == 1 || $showEndTimeList == 1) {
             $showTimeTypeList = 1;
         } else {
             $showStartTimeList = 0;
             $showEndTimeList = 0;
             $showTimeTypeList = 0;
         }
         $showStartDateDetail = $this->arrSettings['showStartDateDetail'] == 1 ? 1 : 0;
         $showEndDateDetail = $this->arrSettings['showEndDateDetail'] == 1 ? 1 : 0;
         $showStartTimeDetail = $this->arrSettings['showStartTimeDetail'] == 1 ? 1 : 0;
         $showEndTimeDetail = $this->arrSettings['showEndTimeDetail'] == 1 ? 1 : 0;
         // reset time values if "no time" is selected
         if ($showStartTimeDetail == 1 || $showEndTimeDetail == 1) {
             $showTimeTypeDetail = 1;
         } else {
             $showStartTimeDetail = 0;
             $showEndTimeDetail = 0;
             $showTimeTypeDetail = 0;
         }
     }
     $access = isset($data['access']) ? intval($data['access']) : 0;
     $priority = isset($data['priority']) ? intval($data['priority']) : 0;
     $placeMediadir = isset($data['placeMediadir']) ? intval($data['placeMediadir']) : 0;
     $hostMediadir = isset($data['hostMediadir']) ? intval($data['hostMediadir']) : 0;
     $price = isset($data['price']) ? contrexx_addslashes(contrexx_strip_tags($data['price'])) : 0;
     $link = isset($data['link']) ? contrexx_addslashes(contrexx_strip_tags($data['link'])) : '';
     $pic = isset($data['picture']) ? contrexx_addslashes(contrexx_strip_tags($data['picture'])) : '';
     $attach = isset($data['attachment']) ? contrexx_addslashes(contrexx_strip_tags($data['attachment'])) : '';
     $catId = isset($data['category']) ? intval($data['category']) : '';
     $showIn = isset($data['showIn']) ? contrexx_addslashes(contrexx_strip_tags(join(",", $data['showIn']))) : '';
     $invited_groups = isset($data['selectedGroups']) ? join(',', $data['selectedGroups']) : '';
     $invited_mails = isset($data['invitedMails']) ? contrexx_addslashes(contrexx_strip_tags($data['invitedMails'])) : '';
     $send_invitation = isset($data['sendInvitation']) ? intval($data['sendInvitation']) : 0;
     $invitationTemplate = isset($data['invitationEmailTemplate']) ? contrexx_input2db($data['invitationEmailTemplate']) : 0;
     $registration = isset($data['registration']) ? intval($data['registration']) : 0;
     $registration_form = isset($data['registrationForm']) ? intval($data['registrationForm']) : 0;
     $registration_num = isset($data['numSubscriber']) ? intval($data['numSubscriber']) : 0;
     $registration_notification = isset($data['notificationTo']) ? contrexx_addslashes(contrexx_strip_tags($data['notificationTo'])) : '';
     $email_template = isset($data['emailTemplate']) ? contrexx_input2db($data['emailTemplate']) : 0;
     $ticket_sales = isset($data['ticketSales']) ? intval($data['ticketSales']) : 0;
     $num_seating = isset($data['numSeating']) ? json_encode(explode(',', $data['numSeating'])) : '';
     $related_hosts = isset($data['selectedHosts']) ? $data['selectedHosts'] : '';
     $locationType = isset($data['eventLocationType']) ? (int) $data['eventLocationType'] : $this->arrSettings['placeData'];
     $hostType = isset($data['eventHostType']) ? (int) $data['eventHostType'] : $this->arrSettings['placeDataHost'];
     $place = isset($data['place']) ? contrexx_input2db(contrexx_strip_tags($data['place'])) : '';
     $street = isset($data['street']) ? contrexx_input2db(contrexx_strip_tags($data['street'])) : '';
     $zip = isset($data['zip']) ? contrexx_input2db(contrexx_strip_tags($data['zip'])) : '';
     $city = isset($data['city']) ? contrexx_input2db(contrexx_strip_tags($data['city'])) : '';
     $country = isset($data['country']) ? contrexx_input2db(contrexx_strip_tags($data['country'])) : '';
     $placeLink = isset($data['placeLink']) ? contrexx_input2db($data['placeLink']) : '';
     $placeMap = isset($data['placeMap']) ? contrexx_input2db($data['placeMap']) : '';
     $update_invitation_sent = $send_invitation == 1;
     if (!empty($placeLink)) {
         if (!preg_match('%^(?:ftp|http|https):\\/\\/%', $placeLink)) {
             $placeLink = "http://" . $placeLink;
         }
     }
     if ($objInit->mode == 'frontend') {
         $unique_id = intval($_REQUEST[self::MAP_FIELD_KEY]);
         if (!empty($unique_id)) {
             $picture = $this->_handleUpload('mapUpload', $unique_id);
             if (!empty($picture)) {
                 $placeMap = $picture;
             }
         }
     }
     $orgName = isset($data['organizerName']) ? contrexx_input2db($data['organizerName']) : '';
     $orgStreet = isset($data['organizerStreet']) ? contrexx_input2db($data['organizerStreet']) : '';
     $orgZip = isset($data['organizerZip']) ? contrexx_input2db($data['organizerZip']) : '';
     $orgCity = isset($data['organizerCity']) ? contrexx_input2db($data['organizerCity']) : '';
     $orgCountry = isset($data['organizerCountry']) ? contrexx_input2db($data['organizerCountry']) : '';
     $orgLink = isset($data['organizerLink']) ? contrexx_input2db($data['organizerLink']) : '';
     $orgEmail = isset($data['organizerEmail']) ? contrexx_input2db($data['organizerEmail']) : '';
     if (!empty($orgLink)) {
         if (!preg_match('%^(?:ftp|http|https):\\/\\/%', $orgLink)) {
             $orgLink = "http://" . $orgLink;
         }
     }
     // create thumb if not exists
     if (!file_exists(\Env::get('cx')->getWebsitePath() . "{$placeMap}.thumb")) {
         $objImage = new \ImageManager();
         $objImage->_createThumb(dirname(\Env::get('cx')->getWebsitePath() . "{$placeMap}") . "/", '', basename($placeMap), 180);
     }
     //frontend picture upload & thumbnail creation
     if ($objInit->mode == 'frontend') {
         $unique_id = intval($_REQUEST[self::PICTURE_FIELD_KEY]);
         $attachmentUniqueId = intval($_REQUEST[self::ATTACHMENT_FIELD_KEY]);
         if (!empty($unique_id)) {
             $picture = $this->_handleUpload('pictureUpload', $unique_id);
             if (!empty($picture)) {
                 //delete thumb
                 if (file_exists("{$this->uploadImgPath}{$pic}.thumb")) {
                     \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$pic}.thumb");
                 }
                 //delete image
                 if (file_exists("{$this->uploadImgPath}{$pic}")) {
                     \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$pic}");
                 }
                 $pic = $picture;
             }
         }
         if (!empty($attachmentUniqueId)) {
             $attachment = $this->_handleUpload('attachmentUpload', $attachmentUniqueId);
             if ($attachment) {
                 //delete file
                 if (file_exists("{$this->uploadImgPath}{$attach}")) {
                     \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$attach}");
                 }
                 $attach = $attachment;
             }
         }
     } else {
         // create thumb if not exists
         if (!file_exists(\Env::get('cx')->getWebsitePath() . "{$pic}.thumb")) {
             $objImage = new \ImageManager();
             $objImage->_createThumb(dirname(\Env::get('cx')->getWebsitePath() . "{$pic}") . "/", '', basename($pic), 180);
         }
     }
     $seriesStatus = isset($data['seriesStatus']) ? intval($data['seriesStatus']) : 0;
     //series pattern
     $seriesStatus = isset($data['seriesStatus']) ? intval($data['seriesStatus']) : 0;
     $seriesType = isset($data['seriesType']) ? intval($data['seriesType']) : 0;
     $seriesPatternCount = 0;
     $seriesPatternWeekday = 0;
     $seriesPatternDay = 0;
     $seriesPatternWeek = 0;
     $seriesPatternMonth = 0;
     $seriesPatternType = 0;
     $seriesPatternDouranceType = 0;
     $seriesPatternEnd = 0;
     $seriesExeptions = '';
     $seriesPatternEndDate = 0;
     if ($seriesStatus == 1) {
         if (!empty($data['seriesExeptions'])) {
             $exeptions = array();
             foreach ($data['seriesExeptions'] as $key => $exeptionDate) {
                 $exeptions[] = date("Y-m-d", parent::getDateTimestamp($exeptionDate, 23, 59));
             }
             sort($exeptions);
             $seriesExeptions = join(",", $exeptions);
         }
         switch ($seriesType) {
             case 1:
                 if ($seriesStatus == 1) {
                     $seriesPatternType = isset($data['seriesDaily']) ? intval($data['seriesDaily']) : 0;
                     if ($seriesPatternType == 1) {
                         $seriesPatternWeekday = 0;
                         $seriesPatternDay = isset($data['seriesDailyDays']) ? intval($data['seriesDailyDays']) : 0;
                     } else {
                         $seriesPatternWeekday = "1111100";
                         $seriesPatternDay = 0;
                     }
                     $seriesPatternWeek = 0;
                     $seriesPatternMonth = 0;
                     $seriesPatternCount = 0;
                 }
                 break;
             case 2:
                 if ($seriesStatus == 1) {
                     $seriesPatternWeek = isset($data['seriesWeeklyWeeks']) ? intval($data['seriesWeeklyWeeks']) : 0;
                     for ($i = 1; $i <= 7; $i++) {
                         if (isset($data['seriesWeeklyDays'][$i])) {
                             $weekdayPattern .= "1";
                         } else {
                             $weekdayPattern .= "0";
                         }
                     }
                     $seriesPatternWeekday = $weekdayPattern;
                     $seriesPatternCount = 0;
                     $seriesPatternDay = 0;
                     $seriesPatternMonth = 0;
                     $seriesPatternType = 0;
                 }
                 break;
             case 3:
                 if ($seriesStatus == 1) {
                     $seriesPatternType = isset($data['seriesMonthly']) ? intval($data['seriesMonthly']) : 0;
                     if ($seriesPatternType == 1) {
                         $seriesPatternMonth = isset($data['seriesMonthlyMonth_1']) ? intval($data['seriesMonthlyMonth_1']) : 0;
                         $seriesPatternDay = isset($data['seriesMonthlyDay']) ? intval($data['seriesMonthlyDay']) : 0;
                         $seriesPatternWeekday = 0;
                     } else {
                         $seriesPatternCount = isset($data['seriesMonthlyDayCount']) ? intval($data['seriesMonthlyDayCount']) : 0;
                         $seriesPatternMonth = isset($data['seriesMonthlyMonth_2']) ? intval($data['seriesMonthlyMonth_2']) : 0;
                         if ($seriesPatternMonth < 1) {
                             // the increment must be at least once a month, otherwise we will end up in a endless loop in the presence
                             $seriesPatternMonth = 1;
                         }
                         $seriesPatternWeekday = isset($data['seriesMonthlyWeekday']) ? $data['seriesMonthlyWeekday'] : '';
                         $seriesPatternDay = 0;
                     }
                     $seriesPatternWeek = 0;
                 }
                 break;
         }
         $seriesPatternDouranceType = isset($data['seriesDouranceType']) ? intval($data['seriesDouranceType']) : 0;
         switch ($seriesPatternDouranceType) {
             case 1:
                 $seriesPatternEnd = 0;
                 break;
             case 2:
                 $seriesPatternEnd = isset($data['seriesDouranceEvents']) ? intval($data['seriesDouranceEvents']) : 0;
                 break;
             case 3:
                 $seriesPatternEndDate = date("Y-m-d H:i:s", parent::getDateTimestamp($data['seriesDouranceDate'], 23, 59));
                 break;
         }
     }
     $formData = array('type' => $type, 'startdate' => $startDate, 'enddate' => $endDate, 'use_custom_date_display' => $useCustomDateDisplay, 'showStartDateList' => $showStartDateList, 'showEndDateList' => $showEndDateList, 'showStartTimeList' => $showStartTimeList, 'showEndTimeList' => $showEndTimeList, 'showTimeTypeList' => $showTimeTypeList, 'showStartDateDetail' => $showStartDateDetail, 'showEndDateDetail' => $showEndDateDetail, 'showStartTimeDetail' => $showStartTimeDetail, 'showEndTimeDetail' => $showEndTimeDetail, 'showTimeTypeDetail' => $showTimeTypeDetail, 'google' => $google, 'access' => $access, 'priority' => $priority, 'price' => $price, 'link' => $link, 'pic' => $pic, 'catid' => $catId, 'attach' => $attach, 'place_mediadir_id' => $placeMediadir, 'host_mediadir_id' => $hostMediadir, 'show_in' => $showIn, 'invited_groups' => $invited_groups, 'invited_mails' => $invited_mails, 'invitation_email_template' => json_encode($invitationTemplate), 'registration' => $registration, 'registration_form' => $registration_form, 'registration_num' => $registration_num, 'registration_notification' => $registration_notification, 'email_template' => json_encode($email_template), 'ticket_sales' => $ticket_sales, 'num_seating' => $num_seating, 'series_status' => $seriesStatus, 'series_type' => $seriesType, 'series_pattern_count' => $seriesPatternCount, 'series_pattern_weekday' => $seriesPatternWeekday, 'series_pattern_day' => $seriesPatternDay, 'series_pattern_week' => $seriesPatternWeek, 'series_pattern_month' => $seriesPatternMonth, 'series_pattern_type' => $seriesPatternType, 'series_pattern_dourance_type' => $seriesPatternDouranceType, 'series_pattern_end' => $seriesPatternEnd, 'series_pattern_end_date' => $seriesPatternEndDate, 'series_pattern_exceptions' => $seriesExeptions, 'all_day' => $allDay, 'location_type' => $locationType, 'host_type' => $hostType, 'place' => $place, 'place_id' => 0, 'place_street' => $street, 'place_zip' => $zip, 'place_city' => $city, 'place_country' => $country, 'place_link' => $placeLink, 'place_map' => $placeMap, 'org_name' => $orgName, 'org_street' => $orgStreet, 'org_zip' => $orgZip, 'org_city' => $orgCity, 'org_country' => $orgCountry, 'org_link' => $orgLink, 'org_email' => $orgEmail, 'invitation_sent' => $update_invitation_sent ? 1 : 0);
     if ($id != 0) {
         $query = \SQL::update("module_{$this->moduleTablePrefix}_event", $formData) . " WHERE id = '{$id}'";
         $objResult = $objDatabase->Execute($query);
         if ($objResult !== false) {
             $this->id = $id;
             $query = "DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_event_field\n                                WHERE event_id = '" . $id . "'";
             $objResult = $objDatabase->Execute($query);
             $query = "DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_event_host\n                                WHERE event_id = '" . $id . "'";
             $objResult = $objDatabase->Execute($query);
         } else {
             return false;
         }
     } else {
         $objFWUser = \FWUser::getFWUserObject();
         $objUser = $objFWUser->objUser;
         if ($objInit->mode == 'frontend') {
             $status = 1;
             $confirmed = $this->arrSettings['confirmFrontendEvents'] == 1 ? 0 : 1;
             $author = $objUser->login() ? intval($objUser->getId()) : 0;
         } else {
             $status = 0;
             $confirmed = 1;
             $author = intval($objUser->getId());
         }
         $formData['status'] = $status;
         $formData['confirmed'] = $confirmed;
         $formData['author'] = $author;
         $query = \SQL::insert("module_{$this->moduleTablePrefix}_event", $formData);
         $objResult = $objDatabase->Execute($query);
         if ($objResult !== false) {
             $id = intval($objDatabase->Insert_ID());
             $this->id = $id;
         } else {
             return false;
         }
     }
     if ($id != 0) {
         foreach ($data['showIn'] as $key => $langId) {
             $title = contrexx_addslashes(contrexx_strip_tags($data['title'][$langId]));
             $description = contrexx_addslashes($data['description'][$langId]);
             if ($convertBBCode) {
                 $description = \Cx\Core\Wysiwyg\Wysiwyg::prepareBBCodeForDb($data['description'][$langId], true);
             }
             $redirect = contrexx_addslashes($data['calendar-redirect'][$langId]);
             if ($type == 0) {
                 $redirect = '';
             } else {
                 $description = '';
             }
             $query = "INSERT INTO " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_event_field\n                            (`event_id`,`lang_id`,`title`, `description`,`redirect`)\n                          VALUES\n                            ('" . intval($id) . "','" . intval($langId) . "','" . $title . "','" . $description . "','" . $redirect . "')";
             $objResult = $objDatabase->Execute($query);
             if ($objResult === false) {
                 return false;
             }
         }
         if (!empty($related_hosts)) {
             foreach ($related_hosts as $key => $hostId) {
                 $query = "INSERT INTO " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_event_host\n                                      (`host_id`,`event_id`) \n                               VALUES ('" . intval($hostId) . "','" . intval($id) . "')";
                 $objResult = $objDatabase->Execute($query);
             }
         }
     }
     if ($send_invitation == 1) {
         $objMailManager = new \Cx\Modules\Calendar\Controller\CalendarMailManager();
         foreach ($invitationTemplate as $templateId) {
             $objMailManager->sendMail(intval($id), \Cx\Modules\Calendar\Controller\CalendarMailManager::MAIL_INVITATION, null, $templateId);
         }
     }
     return true;
 }
 /**
  * Rotates an image clockwise by 90�
  *
  * @global    ADONewConnection
  * @global    array
  * @global    array
  */
 function rotatePicture($intImageId)
 {
     global $objDatabase, $_ARRAYLANG, $_CONFIG;
     if (!function_exists('imagerotate')) {
         $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_GD_LIB_NOT_INSTALLED'];
         return false;
     }
     $objResult = $objDatabase->Execute('SELECT     path,
                                                 quality,
                                                 size_type,
                                                 size_proz,
                                                 size_abs_h,
                                                 size_abs_w
                                         FROM     ' . DBPREFIX . 'module_gallery_pictures
                                         WHERE     id=' . $intImageId);
     $strImagename = $objResult->fields['path'];
     $strOrgPath = $this->strImagePath;
     $strWebpath = $this->strImageWebPath;
     $strThumbPath = $this->strThumbnailPath;
     $strThumbWebpath = $this->strThumbnailWebPath;
     $objImage = new \ImageManager();
     $objImage->loadImage($strOrgPath . $strImagename);
     //Rotate the clockwise
     if ($objImage->rotateImage(270)) {
         //To save the Rotated image
         if ($objImage->saveNewImage($strOrgPath . $strImagename, true)) {
             \Cx\Lib\FileSystem\FileSystem::delete_file($strThumbPath . $strImagename);
         }
         $imageSize = $objImage->_getImageSize($strOrgPath . $strImagename);
         $intOldWidth = $imageSize[0];
         $intOldHeight = $imageSize[1];
         if ($objResult->fields['size_type'] == 'abs') {
             $intNewWidth = intval($this->arrSettings['standard_width_abs']);
             $intNewHeight = intval($this->arrSettings['standard_height_abs']);
             if ($intNewWidth == 0) {
                 // exception if width and height or 0!
                 if ($intNewHeight == 0) {
                     $intNewHeight = 100;
                 }
                 $intNewWidth = round($intOldWidth * $intNewHeight / $intOldHeight, 0);
             } else {
                 if ($intNewHeight == 0) {
                     $intNewHeight = round($intOldHeight * $intNewWidth / $intOldWidth, 0);
                 }
             }
         } else {
             $intNewWidth = round($objResult->fields['size_proz'] / 100 * $intOldWidth, 0);
             $intNewHeight = round($objResult->fields['size_proz'] / 100 * $intOldHeight, 0);
         }
         //Resize the Rotated image
         if ($objImage->resizeImageSave($strOrgPath, $strWebpath, $strImagename, $intNewWidth, $intNewHeight, $objResult->fields['quality'], $strThumbPath, $strThumbWebpath, $strImagename)) {
             if ($objResult->fields['size_type'] == 'abs') {
                 $objDatabase->Execute('    UPDATE     ' . DBPREFIX . 'module_gallery_pictures
                                 SET     size_abs_h=' . $intNewHeight . ',
                                         size_abs_w=' . $intNewWidth . '
                                 WHERE     id=' . $intImageId);
             }
         }
     }
 }
Exemple #5
0
 /**
  * Uploader callback function
  * 
  * @param string  $tempPath    Temp path
  * @param string  $tempWebPath Temp webpath
  * @param string  $data        post data
  * @param integer $uploadId    upload id
  * @param array   $fileInfos   file infos
  * @param object  $response    Upload api response object
  * 
  * @return array $tempPath and $tempWebPath
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     // Delete existing files because we need only one file to upload
     if (\Cx\Lib\FileSystem\FileSystem::exists($tempPath)) {
         foreach (glob($tempPath . '/*') as $file) {
             if (basename($file) == $fileInfos['name']) {
                 continue;
             }
             \Cx\Lib\FileSystem\FileSystem::delete_file($file);
         }
     }
     return array($tempPath, $tempWebPath);
 }
Exemple #6
0
 /**
  * Uploader callback function
  *
  * This is called as soon as uploads have finished.
  *
  * @param string  $tempPath    Path to the temporary directory containing the files at this moment
  * @param string  $tempWebPath Points to the same folder as tempPath, but relative to the webroot
  * @param array   $data        Data given to setData() when creating the uploader
  * @param string  $uploadId    upload id
  * @param array   $fileInfos   uploaded file informations
  * @param object  $response    Upload api response object
  *
  * @return array $tempPath and $tempWebPath
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     // in case uploader has been restricted to only allow one single file to be
     // uploaded, we'll have to clean up any previously uploaded files
     if (count($fileInfos['name'])) {
         // new files have been uploaded -> remove existing files
         if (\Cx\Lib\FileSystem\FileSystem::exists($tempPath)) {
             foreach (glob($tempPath . '/*') as $file) {
                 if (basename($file) == $fileInfos['name']) {
                     continue;
                 }
                 \Cx\Lib\FileSystem\FileSystem::delete_file($file);
             }
         }
     }
     return array($tempPath, $tempWebPath);
 }
Exemple #7
0
 function _deleteMedium($id)
 {
     global $objDatabase;
     $query = "SELECT `thumbnail`\n                  FROM `" . DBPREFIX . "module_podcast_medium`\n                  WHERE `id` = " . $id;
     if (($objRS = $objDatabase->SelectLimit($query, 1)) !== false) {
         $thumbNail = $objRS->fields['thumbnail'];
         if (strpos($thumbNail, '/') !== 0) {
             $thumbNail = '/' . $thumbNail;
         }
         \Cx\Lib\FileSystem\FileSystem::delete_file(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbNail);
     }
     if ($objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_podcast_rel_medium_category WHERE medium_id=" . $id) !== false) {
         if ($objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_podcast_medium WHERE id=" . $id) !== false) {
             return true;
         }
     }
     return false;
 }
Exemple #8
0
 /**
  * Create a thumbnail of a picture.
  *
  * This is very much like {@link _createThumb()}, but provides more
  * parameters.  Both the width and height of the thumbnail may be
  * specified; the picture will still be scaled to fit within the given
  * sizes while keeping the original width/height ratio.
  * In addition to that, this method tries to delete an existing
  * thumbnail before attempting to write the new one.
  * Note that all "Path" parameters are required to bring along their
  * own trailing slash.
  * 
  * @param   string  $strPath        The image file folder
  * @param   string  $strWebPath     The image file web folder
  * @param   string  $file           The image file name
  * @param   integer $maxWidth       The maximum width of the image
  * @param   integer $maxHeight      The maximum height of the image
  * @param   integer $quality        The desired jpeg thumbnail quality
  * @param   string  $thumbNailSuffix  Suffix of the thumbnail. Default is 'thumb'
  * @param   string  $strPathNew     Image file store folder. Default is $strPath
  * @param   string  $strWebPathNew  Image file web store folder. Default is $strWebPath
  * @param   string  $fileNew        Image file store name. Default is $file
  * @return  bool                    True on success, false otherwise.
  */
 function _createThumbWhq($strPath, $strWebPath, $file, $maxWidth = 80, $maxHeight = 80, $quality = 90, $thumbNailSuffix = '.thumb', $strPathNew = null, $strWebPathNew = null, $fileNew = null)
 {
     // Do *NOT* strip subfolders from the file name!
     // This would break correct operation in some places (shop)
     // Fix your own code to provide the file name only if you need to.
     //$file      = basename($file);
     if (empty($fileNew)) {
         $fileNew = $file;
     }
     if (empty($strPathNew)) {
         $strPathNew = $strPath;
     }
     if (empty($strWebPathNew)) {
         $strWebPathNew = $strWebPath;
     }
     $tmpSize = getimagesize($strPath . $file);
     // reset the ImageManager
     $this->imageCheck = 1;
     $width = $tmpSize[0];
     $height = $tmpSize[1];
     $widthRatio = $width / $maxWidth;
     $heightRatio = $height / $maxHeight;
     $thumbWidth = 0;
     $thumbHeight = 0;
     if ($widthRatio < $heightRatio) {
         $thumbHeight = $maxHeight;
         $thumbWidth = $width * $maxHeight / $height;
     } else {
         $thumbWidth = $maxWidth;
         $thumbHeight = $height * $maxWidth / $width;
     }
     if (!$this->loadImage($strPath . $file)) {
         return false;
     }
     if (!$this->resizeImage($thumbWidth, $thumbHeight, $quality)) {
         return false;
     }
     if (is_file($strPathNew . $fileNew . $thumbNailSuffix)) {
         if (!\Cx\Lib\FileSystem\FileSystem::delete_file($strPathNew . $fileNew . $thumbNailSuffix)) {
             return false;
         }
     }
     if (!$this->saveNewImage($strPathNew . $fileNew . $thumbNailSuffix)) {
         return false;
     }
     if (!\Cx\Lib\FileSystem\FileSystem::makeWritable($strPathNew . $fileNew . $thumbNailSuffix)) {
         return false;
     }
     return true;
 }
 /**
  * Uploader callback function
  * 
  * @param string  $tempPath    Temp path
  * @param string  $tempWebPath Temp webpath
  * @param string  $data        post data
  * @param integer $uploadId    upload id
  * @param array   $fileInfos   file infos
  * @param object  $response    Upload api response object
  * 
  * @return array path and webpath
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     global $objInit;
     $lang = $objInit->loadLanguageData('Calendar');
     $tup = self::getTemporaryUploadPath($data['field_name'], $uploadId);
     $path = $tup[0] . '/' . $tup[2];
     $webPath = $tup[1] . '/' . $tup[2];
     $arrFiles = array();
     //get allowed file types
     $arrAllowedFileTypes = array();
     if (imagetypes() & IMG_GIF) {
         $arrAllowedFileTypes[] = 'gif';
     }
     if (imagetypes() & IMG_JPG) {
         $arrAllowedFileTypes[] = 'jpg';
         $arrAllowedFileTypes[] = 'jpeg';
     }
     if (imagetypes() & IMG_PNG) {
         $arrAllowedFileTypes[] = 'png';
     }
     $h = opendir($tempPath);
     if ($h) {
         while (false != ($file = readdir($h))) {
             $info = pathinfo($file);
             //skip . and ..
             if ($file == '.' || $file == '..') {
                 continue;
             }
             //delete unwanted files
             if (!in_array(strtolower($info['extension']), $arrAllowedFileTypes) && $data['allowImageOnly']) {
                 $response->addMessage(\Cx\Core_Modules\Upload\Controller\UploadResponse::STATUS_ERROR, $lang["TXT_CALENDAR_IMAGE_UPLOAD_ERROR"], $file);
                 \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $file);
                 continue;
             }
             $arrFiles[] = $file;
         }
         closedir($h);
     }
     // Delete existing files because we need only one file to upload
     if (!empty($arrFiles)) {
         $h = opendir($path);
         if ($h) {
             while (false != ($file = readdir($h))) {
                 //skip . and ..
                 if ($file == '.' || $file == '..') {
                     continue;
                 }
                 \Cx\Lib\FileSystem\FileSystem::delete_file($path . '/' . $file);
             }
         }
     }
     return array($path, $webPath);
 }
 /**
  * this is called as soon as uploads have finished.
  * takes care of moving them to the right folder
  * 
  * @return string the directory to move to
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     $path = $data['path'];
     $webPath = $data['webPath'];
     //we remember the names of the uploaded files here. they are stored in the session afterwards,
     //so we can later display them highlighted.
     $arrFiles = array();
     //rename files, delete unwanted
     $arrFilesToRename = array();
     //used to remember the files we need to rename
     $h = opendir($tempPath);
     if ($h) {
         while (false !== ($file = readdir($h))) {
             //delete potentially malicious files
             // TODO: this is probably an overhead, because the uploader might already to this. doesn't it?
             if (!\FWValidator::is_file_ending_harmless($file)) {
                 @unlink($file);
                 continue;
             }
             if (self::isIllegalFileName($file)) {
                 $response->addMessage(\Cx\Core_Modules\Upload\Controller\UploadResponse::STATUS_ERROR, "You are not able to create the requested file.");
                 \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $file);
                 continue;
             }
             //skip . and ..
             if ($file == '.' || $file == '..') {
                 continue;
             }
             //clean file name
             $newName = $file;
             \Cx\Lib\FileSystem\FileSystem::clean_path($newName);
             //check if file needs to be renamed
             if (file_exists($path . $newName)) {
                 $info = pathinfo($newName);
                 $exte = $info['extension'];
                 $exte = !empty($exte) ? '.' . $exte : '';
                 $part1 = $info['filename'];
                 if (empty($_REQUEST['uploadForceOverwrite']) || !intval($_REQUEST['uploadForceOverwrite'] > 0)) {
                     $newName = $part1 . '_' . time() . $exte;
                 }
             }
             //if the name has changed, the file needs to be renamed afterwards
             if ($newName != $file) {
                 $arrFilesToRename[$file] = $newName;
             }
             array_push($arrFiles, $newName);
         }
     }
     //rename files where needed
     foreach ($arrFilesToRename as $oldName => $newName) {
         rename($tempPath . '/' . $oldName, $tempPath . '/' . $newName);
     }
     //remeber the uploaded files
     $files = $_SESSION["media_upload_files_{$uploadId}"];
     $_SESSION["media_upload_files_{$uploadId}"] = array_merge($arrFiles, $files ? $files->toArray() : []);
     /* unwanted files have been deleted, unallowed filenames corrected.
        we can now simply return the desired target path, as only valid
        files are present in $tempPath                                   */
     return array($data['path'], $data['webPath']);
 }
 /**
  * the upload is finished
  * rewrite the names
  * write the uploaded files to the database
  *
  * @param string     $tempPath    the temporary file path
  * @param string     $tempWebPath the temporary file path which is accessable by web browser
  * @param array      $data        the data which are attached by uploader init method
  * @param integer    $uploadId    the upload id
  * @param array      $fileInfos   the file infos  
  * @param String     $response    the respose
  * 
  * @return array the target paths
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     global $objDatabase, $_ARRAYLANG, $_CONFIG, $objInit;
     $arrFiles = array();
     //get allowed file types
     $arrAllowedFileTypes = array();
     $arrAllowedFileTypes[] = 'csv';
     $depositionTarget = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteMediaCrmPath() . '/';
     //target folder
     $fileName = $_POST['name'];
     $h = opendir($tempPath);
     if ($h) {
         while (false != ($file = readdir($h))) {
             $info = pathinfo($file);
             //skip . and ..
             if ($file == '.' || $file == '..') {
                 continue;
             }
             //delete unwanted files
             $sizeLimit = 10485760;
             $size = filesize($tempPath . '/' . $file);
             if ($size > $sizeLimit) {
                 $response->addMessage(\Cx\Core_Modules\Upload\Controller\UploadResponse::STATUS_ERROR, "Server error. Increase post_max_size and upload_max_filesize to {$size}.");
                 \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $file);
                 continue;
             }
             if (!in_array(strtolower($info['extension']), $arrAllowedFileTypes)) {
                 $response->addMessage(\Cx\Core_Modules\Upload\Controller\UploadResponse::STATUS_ERROR, 'Please choose a csv to upload');
                 \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $file);
                 continue;
             }
             if ($file != '..' && $file != '.') {
                 //do not overwrite existing files.
                 $prefix = '';
                 while (file_exists($depositionTarget . $prefix . $file)) {
                     if (empty($prefix)) {
                         $prefix = 0;
                     }
                     $prefix++;
                 }
                 // move file
                 try {
                     $objFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $file);
                     $objFile->copy($depositionTarget . $prefix . $file, false);
                     $fileName = $prefix . $file;
                     if (!empty($fileName)) {
                         list($file, $ext) = split('[.]', $fileName);
                         if ($ext == 'csv') {
                             $_SESSION['importFilename'] = $fileName;
                         }
                     }
                 } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                     \DBG::msg($e->getMessage());
                 }
             }
             $arrFiles[] = $file;
         }
         closedir($h);
     }
     return array($tempPath, $tempWebPath);
 }
 /**
  * Upload handler.
  *
  * @param $params
  *
  * @return array
  * @throws UploaderException
  */
 public function upload($params)
 {
     global $_ARRAYLANG;
     $id = null;
     if (isset($params['get']['id']) && preg_match('/^[a-z0-9]+$/i', $params['get']['id'])) {
         $id = $params['get']['id'];
         $uploadedFileCount = isset($params['get']['uploadedFileCount']) ? intval($params['get']['uploadedFileCount']) : 0;
         $path = $_SESSION->getTempPath() . '/' . $id . '/';
         $tmpPath = $path;
     } elseif (isset($params['post']['path'])) {
         $path_part = explode("/", $params['post']['path'], 2);
         $mediaSourceManager = $this->cx->getMediaSourceManager();
         $path = $mediaSourceManager->getMediaTypePathsbyNameAndOffset($path_part[0], 0) . '/' . $path_part[1];
         $tmpPath = $_SESSION->getTempPath();
     } else {
         return array('OK' => 0, 'error' => array('message' => 'No id specified'));
     }
     $allowedExtensions = \Cx\Core_Modules\Uploader\Model\Entity\Uploader::$allowedExtensions;
     if (isset($_SESSION['uploader']['handlers'][$id]['config']['allowed-extensions'])) {
         $allowedExtensions = $_SESSION['uploader']['handlers'][$id]['config']['allowed-extensions'];
     }
     $uploader = UploaderController::handleRequest(array('allow_extensions' => explode(', ', $allowedExtensions), 'target_dir' => $path, 'tmp_dir' => $tmpPath));
     $fileLocation = array($uploader['path'], str_replace($this->cx->getWebsitePath(), '', $uploader['path']));
     $response = new UploadResponse();
     if (isset($_SESSION['uploader']['handlers'][$id]['callback'])) {
         /**
          * @var $callback RecursiveArrayAccess
          * @var $data RecursiveArrayAccess
          */
         $callback = $_SESSION['uploader']['handlers'][$id]['callback'];
         $data = $_SESSION['uploader']['handlers'][$id]['data'];
         if (isset($_SESSION['uploader']['handlers'][$id]['config']['upload-limit']) && $_SESSION['uploader']['handlers'][$id]['config']['upload-limit'] <= $uploadedFileCount) {
             return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_CORE_MODULE_UPLOADER_MAX_LIMIT_REACHED']);
         }
         if (!is_string($callback)) {
             $callback = $callback->toArray();
         }
         if ($data) {
             $data = $data->toArray();
         }
         $filePath = dirname($uploader['path']);
         if (!is_array($callback)) {
             $class = new \ReflectionClass($callback);
             if ($class->implementsInterface('\\Cx\\Core_Modules\\Uploader\\Model\\UploadCallbackInterface')) {
                 /**
                  * @var \Cx\Core_Modules\Uploader\Model\UploadCallbackInterface $callbackInstance
                  */
                 $callbackInstance = $class->newInstance($this->cx);
                 $fileLocation = $callbackInstance->uploadFinished($filePath, str_replace($this->cx->getWebsiteTempPath(), $this->cx->getWebsiteTempWebPath(), $filePath), $data, $id, $uploader, $response);
             }
         } else {
             $fileLocation = call_user_func(array($callback[1], $callback[2]), $filePath, str_replace($this->cx->getWebsiteTempPath(), $this->cx->getWebsiteTempWebPath(), $filePath), $data, $id, $uploader, $response);
         }
         \Cx\Lib\FileSystem\FileSystem::move($uploader['path'], $fileLocation[0] . '/' . $uploader['name'], true);
         \Cx\Lib\FileSystem\FileSystem::delete_file($uploader['path']);
         if (isset($fileLocation[2])) {
             $uploader['name'] = $fileLocation[2];
         }
         $fileLocation = array($fileLocation[0] . '/' . $uploader['name'], $fileLocation[1] . '/' . $uploader['name']);
     }
     if ($response->getWorstStatus()) {
         $result = $response->getResponse();
         return array('OK' => 0, 'file' => $fileLocation, 'response' => $result['messages']);
     }
     if (isset($uploader['error'])) {
         throw new UploaderException(UploaderController::getErrorCode());
     } else {
         return array('OK' => 1, 'file' => $fileLocation);
     }
 }
 public function removeFile(File $file)
 {
     global $_ARRAYLANG;
     if ($file->getExtension() == '' && is_dir($this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName())) {
         $filename = $file->getName();
     } else {
         $filename = $file->getName() . '.' . $file->getExtension();
     }
     $strPath = $file->getPath();
     if (!empty($filename) && !empty($strPath)) {
         if (is_dir($this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName())) {
             if (\Cx\Lib\FileSystem\FileSystem::delete_folder($this->rootPath . $strPath . $filename, true)) {
                 return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_SUCCESSFULLY_REMOVED'], $filename);
             } else {
                 return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_UNSUCCESSFULLY_REMOVED'], $filename);
             }
         } else {
             if (\Cx\Lib\FileSystem\FileSystem::delete_file($this->rootPath . '/' . $strPath . '/' . $filename)) {
                 return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_REMOVED'], $filename);
             } else {
                 return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename);
             }
         }
     }
     return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename);
 }
Exemple #14
0
 /**
  * Get the thumbnail generation progress from the temp file
  */
 function getThumbProgress()
 {
     // release the locks, session not needed
     $session = \cmsSession::getInstance();
     $session->releaseLocks();
     session_write_close();
     $key = isset($_GET['key']) ? $_GET['key'] : '';
     $processFile = $session->getTempPath() . '/progress' . $key . '.txt';
     $process = 0;
     if (file_exists($processFile)) {
         $process = file_get_contents($processFile);
         if ($process == 100) {
             \Cx\Lib\FileSystem\FileSystem::delete_file($processFile);
         }
     }
     echo $process;
     die;
 }
 /**
  * @param File $file
  *
  * @return array
  */
 public function removeThumbnails(File $file)
 {
     if (!$this->isImage($file->getExtension())) {
         return;
     }
     $iterator = new \RegexIterator(new \DirectoryIterator($this->getFullPath($file)), '/' . preg_quote($file->getName(), '/') . '.thumb_[a-z]+/');
     foreach ($iterator as $thumbnail) {
         \Cx\Lib\FileSystem\FileSystem::delete_file($thumbnail);
     }
 }
 /**
  * Create all the thumbnails for a picture.
  *
  * @param string        $path          Path to the file. This can be a virtual path or a absolute path.
  * @param string        $fileNamePlain Plain file name without extension
  * @param string        $fileExtension Extension of the file
  * @param \ImageManager $imageManager
  *
  * <code>
  * <?php
  * \Cx\Core_Modules\MediaBrowser\Model\FileSystem::createThumbnail(
  *      'files/',
  *      'Django,
  *      'jpg',
  *      new ImageManager() // Please recycle the instance and don't create a new anonymous instance for each call.
  *                         // This is just a simple example.
  * );
  * ?>
  * </code>
  *
  * @param bool          $generateThumbnailByRatio
  * @param bool          $force Force creation of new Thumbnails. This overwrites any existing thumbnail.
  *
  * @return array Array with the relative paths to the thumbnails.
  */
 public function createThumbnail($path, $fileNamePlain, $fileExtension, \ImageManager $imageManager, $generateThumbnailByRatio = false, $force = false)
 {
     $thumbnails = array();
     foreach ($this->getThumbnails() as $thumbnail) {
         if ($force) {
             \Cx\Lib\FileSystem\FileSystem::delete_file(MediaSourceManager::getAbsolutePath($path) . '/' . $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension);
         } elseif (\Cx\Lib\FileSystem\FileSystem::exists(MediaSourceManager::getAbsolutePath($path) . '/' . $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension)) {
             $thumbnails[] = $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension;
             continue;
         }
         if ($imageManager->_createThumb(MediaSourceManager::getAbsolutePath($path) . '/', '', $fileNamePlain . '.' . $fileExtension, $thumbnail['size'], $thumbnail['quality'], $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension, $generateThumbnailByRatio)) {
             $thumbnails[] = $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension;
             continue;
         }
     }
     return $thumbnails;
 }
 /**
  * delete the file or directory
  * 
  * @param array $params supplied arguments from JsonData-request
  * @return string
  */
 public function delete($params)
 {
     global $_ARRAYLANG, $objInit;
     $operation = isset($params['post']['reset']) && !empty($params['post']['reset']) ? 'RESET' : 'DELETE';
     $_ARRAYLANG = $objInit->loadLanguageData('ViewManager');
     if (empty($params['post']['themes']) || empty($params['post']['themesPage'])) {
         return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS']);
     }
     $filePath = $params['post']['themesPage'];
     $currentThemeFolder = \Env::get('cx')->getWebsiteThemesPath() . '/' . $params['post']['themes'] . '/';
     $pathStripped = ltrim($params['post']['themesPage'], '/');
     if (empty($pathStripped)) {
         return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS']);
     }
     if (!\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $filePath) && \Cx\Core\ViewManager\Controller\ViewManager::isFileTypeComponent($filePath)) {
         // resolve the component file
         $componentFilePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($filePath, false);
         if ($componentFilePath && \Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $componentFilePath)) {
             // file exists
             $filePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($filePath, false);
         } else {
             // file not exists may be a folder
             $filePath = \Cx\Core\ViewManager\Controller\ViewManager::replaceComponentFolderByItsType($filePath);
         }
     }
     if (\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $filePath)) {
         if (is_dir($currentThemeFolder . $filePath)) {
             $status = \Cx\Lib\FileSystem\FileSystem::delete_folder($currentThemeFolder . $filePath, true);
             $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FOLDER_' . $operation . '_SUCCESS'], contrexx_input2xhtml($pathStripped));
         } else {
             $status = \Cx\Lib\FileSystem\FileSystem::delete_file($currentThemeFolder . $filePath);
             $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FILE_' . $operation . '_SUCCESS'], contrexx_input2xhtml($pathStripped));
         }
         if (!$status) {
             return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_' . $operation . '_FAILED']);
         }
         return array('status' => 'success', 'reload' => true, 'message' => $succesMessage);
     }
     return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_FILE_NOT_EXITS'], contrexx_input2xhtml($filePath)));
 }
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
     $imageUrl = clone \Env::get("Resolver")->getUrl();
     // get the image url
     $files = array();
     $directory = \Env::get('Resolver')->getCmd();
     if ($directory != 'Downloads') {
         $targetPath = $cx->getWebsiteMediaFileSharingPath() . '/' . (!empty($directory) ? $directory . '/' : '');
         $targetPathWeb = $cx->getWebsiteMediaFileSharingWebPath() . '/' . (!empty($directory) ? $directory . '/' : '');
     } else {
         $targetPath = $cx->getWebsiteImagesDownloadsPath() . '/';
         $targetPathWeb = $cx->getWebsiteImagesDownloadsWebPath() . '/';
     }
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     $dirTempPath = $tup[0] . '/' . $tup[2] . '/';
     //get the tmp/$uploadId files
     foreach (glob($dirTempPath . '/*') as $uploadedFile) {
         $file = basename($uploadedFile);
         $uploadedFileName = $fileSystem->copyFile($dirTempPath, $file, $targetPath, $file, false);
         if ($uploadedFileName === 'error') {
             continue;
         }
         \Cx\Lib\FileSystem\FileSystem::delete_file($dirTempPath . '/' . $file);
         $uploadedFileSource = $targetPathWeb . $uploadedFileName;
         $hash = self::createHash();
         $check = self::createCheck($hash);
         $objResult = $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `cmd`, `hash`, `check`, `upload_id`)\n                                VALUES (\n                                    '" . contrexx_raw2db($uploadedFileName) . "',\n                                    '" . contrexx_raw2db($uploadedFileSource) . "',\n                                    '" . contrexx_raw2db($directory) . "',\n                                    '" . contrexx_raw2db($hash) . "',\n                                    '" . contrexx_raw2db($check) . "',\n                                    '" . contrexx_input2int($uploadId) . "'\n                                )");
         if (!$objResult) {
             continue;
         }
         $imageUrl->setParam("act", "image");
         $imageUrl->setParam("hash", $hash);
         $info = pathinfo($cx->getWebsiteOffsetPath() . $uploadedFileSource, PATHINFO_EXTENSION);
         // if the file is an image show a thumbnail of the image
         if (!in_array(strtoupper($info), array('JPEG', 'JPG', 'TIFF', 'GIF', 'BMP', 'PNG'))) {
             $imageUrl = false;
         }
         $fieldId = $objDatabase->Insert_ID();
         $files[] = array("name" => $uploadedFileName, "image" => $imageUrl->toString(), "download" => parent::getDownloadLink($fieldId), "delete" => parent::getDeleteLink($fieldId));
     }
     return $files;
 }
 /**
  * Return whether file is valid to show or not
  *
  * @param string $filePath  Folder path to the file
  * @param string $fileName  File name
  *
  * @return boolean True when file is valid to show, False otherwise
  */
 public function isFileValidToShow($filePath, $fileName)
 {
     if (empty($filePath) || empty($fileName) || self::isIllegalFileName($fileName)) {
         return false;
     }
     if (preg_match("/(?:\\.(?:thumb_thumbnail|thumb_medium|thumb_large)\\.[^.]+\$)|(?:\\.thumb)\$/i", $fileName)) {
         $originalFileName = preg_replace("/(?:\\.(?:thumb_thumbnail|thumb_medium|thumb_large)(\\.[^.]+)\$)|(?:\\.thumb)\$/mi", "\$1", $fileName);
         if (!\Cx\Lib\FileSystem\FileSystem::exists($filePath . '/' . $originalFileName)) {
             \Cx\Lib\FileSystem\FileSystem::delete_file($filePath . '/' . $fileName);
         }
         return false;
     }
     return true;
 }
 /**
  * Remove a preset.
  *
  * @param $name
  */
 public function remove($name)
 {
     \Cx\Lib\FileSystem\FileSystem::delete_file($this->path . '/options/presets/' . $name . '.yml');
 }
 function deleteFormEntry($id)
 {
     global $objDatabase;
     //let's search for uploaded files left.
     $rs = $objDatabase->Execute("SELECT `d`.`id_form`, `sd`.`formvalue`\n                                     FROM `" . DBPREFIX . "module_contact_form_data` AS `d`\n                                        LEFT JOIN\n                                            `" . DBPREFIX . "module_contact_form_submit_data` AS `sd`\n                                        ON\n                                            `d`.`id` = `sd`.`id_entry`\n                                        INNER JOIN\n                                             `" . DBPREFIX . "module_contact_form_field` AS `f`\n                                        ON\n                                            `f`.`id` = `sd`.`id_field`\n                                        AND\n                                            `f`.`type` IN ('multi_file', 'file')\n                                        WHERE `d`.`id`=" . $id);
     if ($rs) {
         while (!$rs->EOF) {
             $data = $rs->fields['formvalue'];
             $formId = $rs->fields['id_form'];
             //get all form data into arrData
             $arrData = array();
             foreach (explode(';', $data) as $keyValue) {
                 $arrTmp = explode(',', $keyValue);
                 $arrData[base64_decode($arrTmp[0])] = base64_decode($arrTmp[1]);
             }
             //load contact form fields - we need to know which ones have the type 'file'
             $this->initContactForms();
             $arrFormFields = $this->getFormFields($formId);
             foreach ($arrFormFields as $arrField) {
                 //see if it's a file field...
                 if ($arrField['type'] == 'file') {
                     //...and delete the files if yes:
                     $val = isset($arrData[$arrField['name']]) ? $arrData[$arrField['name']] : $data;
                     if (strpos($val, '*')) {
                         //new style entry, multiple files
                         $arrFiles = explode('*', $val);
                     } else {
                         //old style entry, single file
                         $arrFiles = array($val);
                     }
                     //nice, we have all the files. delete them.
                     foreach ($arrFiles as $file) {
                         \Cx\Lib\FileSystem\FileSystem::delete_file(\Env::get('cx')->getWebsiteDocumentRootPath() . $file);
                     }
                 }
             }
             $rs->MoveNext();
         }
     }
     $objDatabase->Execute("DELETE `d`, `sd` FROM\n                                `" . DBPREFIX . "module_contact_form_data` AS `d`\n                               LEFT JOIN\n                                `" . DBPREFIX . "module_contact_form_submit_data` AS `sd`\n                               ON\n                                `d`.`id` = `sd`.`id_entry`\n                               WHERE `d`.`id`=" . $id);
 }
 /**
  * clean up the database and shared files
  * deletes expired files and none existing files
  *
  * @static
  */
 public static function cleanUp()
 {
     global $objDatabase;
     $arrToDelete = array();
     // get all files from database
     $objFiles = $objDatabase->Execute("SELECT `id`, `source`, `expiration_date` FROM " . DBPREFIX . "module_filesharing");
     if ($objFiles !== false) {
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         while (!$objFiles->EOF) {
             // if the file is expired or does not exist
             if ($objFiles->fields["expiration_date"] < date('Y-m-d H:i:s') && $objFiles->fields["expiration_date"] != NULL || !file_exists($cx->getWebsitePath() . $cx->getWebsiteOffsetPath() . $objFiles->fields["source"])) {
                 $fileExists = file_exists($cx->getWebsitePath() . $cx->getWebsiteOffsetPath() . $objFiles->fields["source"]);
                 // if the file is only expired delete the file from directory
                 if ($fileExists) {
                     \Cx\Lib\FileSystem\FileSystem::delete_file($cx->getWebsitePath() . $cx->getWebsiteOffsetPath() . $objFiles->fields["source"]);
                 }
                 $arrToDelete[] = $objFiles->fields["id"];
             }
             $objFiles->moveNext();
         }
     }
     // delete all expired or not existing files
     if (!empty($arrToDelete)) {
         $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_filesharing WHERE `id` IN (" . implode(',', $arrToDelete) . ")");
     }
 }
Exemple #23
0
/**
 * Cloudrexx
 *
 * @link      http://www.cloudrexx.com
 * @copyright Cloudrexx AG 2007-2015
 *
 * According to our dual licensing model, this program can be used either
 * under the terms of the GNU Affero General Public License, version 3,
 * or under a proprietary license.
 *
 * The texts of the GNU Affero General Public License with an additional
 * permission and of our proprietary license can be found at and
 * in the LICENSE file you have received along with this program.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * "Cloudrexx" is a registered trademark of Cloudrexx AG.
 * The licensing of the program under the AGPLv3 does not imply a
 * trademark license. Therefore any rights, title and interest in
 * our trademarks remain entirely with us.
 */
function _coreUpdate()
{
    global $objUpdate, $objDatabase, $_ARRAYLANG, $_CORELANG, $_CONFIG;
    $query = "SELECT `id` FROM `" . DBPREFIX . "languages` WHERE `charset` != 'UTF-8'";
    $objResult = $objDatabase->Execute($query);
    if ($objResult !== false) {
        while (!$objResult->EOF) {
            $query = "UPDATE `" . DBPREFIX . "languages` SET `charset` = 'UTF-8' WHERE `id`=" . $objResult->fields['id'];
            if ($objDatabase->Execute($query) === false) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            $objResult->MoveNext();
        }
    } else {
        return _databaseError($query, $objDatabase->ErrorMsg());
    }
    $query = "SELECT `group_id` FROM `" . DBPREFIX . "access_group_static_ids` WHERE `access_id` = '5' GROUP BY `group_id`";
    $objGroup = $objDatabase->Execute($query);
    if ($objGroup !== false) {
        while (!$objGroup->EOF) {
            $query = "INSERT IGNORE INTO `" . DBPREFIX . "access_group_static_ids` (`access_id`, `group_id`) VALUES ('127', '" . $objGroup->fields['group_id'] . "')";
            if ($objDatabase->Execute($query) === false) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            $objGroup->MoveNext();
        }
    } else {
        return _databaseError($query, $objDatabase->ErrorMsg());
    }
    /*if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0')) {
            $query = "SELECT `catid` FROM `".DBPREFIX."content_navigation`";
            $objContentNavigation = $objDatabase->Execute($query);
            if ($objContentNavigation !== false) {
                $arrContentSiteIds = array();
                while (!$objContentNavigation->EOF) {
                    array_push($arrContentSiteIds, $objContentNavigation->fields['catid']);
                    $objContentNavigation->MoveNext();
                }
    
                $query = "DELETE FROM `".DBPREFIX."content` WHERE `id` != ".implode(' AND `id` != ', $arrContentSiteIds);
                if ($objDatabase->Execute($query) === false) {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
    
            try {
                \Cx\Lib\UpdateUtil::table(
                    DBPREFIX.'content_navigation',
                    array(
                        'catid'                  => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true),
                        'is_validated'           => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '1'),
                        'parcat'                 => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'catname'                => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''),
                        'target'                 => array('type' => 'VARCHAR(10)', 'notnull' => true, 'default' => ''),
                        'displayorder'           => array('type' => 'SMALLINT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '1000'),
                        'displaystatus'          => array('type' => 'SET(\'on\',\'off\')', 'notnull' => true, 'default' => 'on'),
                        'activestatus'           => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '1'),
                        'cachingstatus'          => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '1'),
                        'username'               => array('type' => 'VARCHAR(40)', 'notnull' => true, 'default' => ''),
                        'changelog'              => array('type' => 'INT(14)', 'notnull' => false),
                        'cmd'                    => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''),
                        'lang'                   => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1'),
                        'module'                 => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'startdate'              => array('type' => 'DATE', 'notnull' => true, 'default' => '0000-00-00'),
                        'enddate'                => array('type' => 'DATE', 'notnull' => true, 'default' => '0000-00-00'),
                        'protected'              => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '0'),
                        'frontend_access_id'     => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'backend_access_id'      => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'themes_id'              => array('type' => 'INT(4)', 'notnull' => true, 'default' => '0'),
                        'css_name'               => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''),
                        'custom_content'         => array('type' => 'VARCHAR(64)', 'after' => 'css_name', 'default' => '')
                    ),
                    array(
                        'parcat'                 => array('fields' => array('parcat')),
                        'module'                 => array('fields' => array('module')),
                        'catname'                => array('fields' => array('catname'))
                    )
                );
    
                \Cx\Lib\UpdateUtil::table(
                    DBPREFIX.'content_navigation_history',
                    array(
                        'id'                     => array('type' => 'INT(7)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true),
                        'is_active'              => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '0'),
                        'catid'                  => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'parcat'                 => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'catname'                => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''),
                        'target'                 => array('type' => 'VARCHAR(10)', 'notnull' => true, 'default' => ''),
                        'displayorder'           => array('type' => 'SMALLINT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '1000'),
                        'displaystatus'          => array('type' => 'SET(\'ON\',\'OFF\')', 'notnull' => true, 'default' => 'on'),
                        'activestatus'           => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '1'),
                        'cachingstatus'          => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '1'),
                        'username'               => array('type' => 'VARCHAR(40)', 'notnull' => true, 'default' => ''),
                        'changelog'              => array('type' => 'INT(14)', 'notnull' => false),
                        'cmd'                    => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''),
                        'lang'                   => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1'),
                        'module'                 => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'startdate'              => array('type' => 'DATE', 'notnull' => true, 'default' => '0000-00-00'),
                        'enddate'                => array('type' => 'DATE', 'notnull' => true, 'default' => '0000-00-00'),
                        'protected'              => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '0'),
                        'frontend_access_id'     => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'backend_access_id'      => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'default' => '0'),
                        'themes_id'              => array('type' => 'INT(4)', 'notnull' => true, 'default' => '0'),
                        'css_name'               => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''),
                        'custom_content'         => array('type' => 'VARCHAR(64)', 'after' => 'css_name', 'default' => '')
                    ),
                    array(
                        'catid'                  => array('fields' => array('catid'))
                    )
                );
            } catch (\Cx\Lib\UpdateException $e) {
                return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
            }
        }*/
    // migrate modules table to new scheme
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'modules', array('id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => false), 'name' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => '', 'after' => 'id'), 'distributor' => array('type' => 'CHAR(50)', 'after' => 'name'), 'description_variable' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => '', 'after' => 'distributor'), 'status' => array('type' => 'SET(\'y\',\'n\')', 'notnull' => true, 'default' => 'n', 'after' => 'description_variable'), 'is_required' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'status'), 'is_core' => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '0', 'after' => 'is_required'), 'is_active' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'is_core'), 'is_licensed' => array('type' => 'TINYINT(1)', 'after' => 'is_active')), array('id' => array('fields' => array('id'), 'type' => 'UNIQUE')));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'log', array('id' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'userid' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => false), 'datetime' => array('type' => 'datetime', 'notnull' => false, 'default' => '0000-00-00 00:00:00'), 'useragent' => array('type' => 'VARCHAR(250)', 'notnull' => false, 'default_expr' => 'NULL'), 'userlanguage' => array('type' => 'VARCHAR(250)', 'notnull' => false, 'default_expr' => 'NULL'), 'remote_addr' => array('type' => 'VARCHAR(250)', 'notnull' => false, 'default_expr' => 'NULL'), 'remote_host' => array('type' => 'VARCHAR(250)', 'notnull' => false, 'default_expr' => 'NULL'), 'http_via' => array('type' => 'VARCHAR(250)'), 'http_client_ip' => array('type' => 'VARCHAR(250)'), 'http_x_forwarded_for' => array('type' => 'VARCHAR(250)'), 'referer' => array('type' => 'VARCHAR(250)')));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /**********************************************
     *                                            *
     * MIGRATE BACKEND_AREAS TO NEW ACCESS SYSTEM *
     * BUGFIX: Add UNIQUE key on access_id        *
     *                                            *
     *********************************************/
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'backend_areas', array('area_id' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'parent_area_id' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'type' => array('type' => 'ENUM(\'group\',\'function\',\'navigation\')', 'notnull' => false, 'default' => 'navigation'), 'scope' => array('type' => 'ENUM(\'global\',\'frontend\',\'backend\')', 'notnull' => true, 'default' => 'global', 'after' => 'type'), 'area_name' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default_expr' => 'NULL'), 'is_active' => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '1'), 'uri' => array('type' => 'VARCHAR(255)'), 'target' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => '_self'), 'module_id' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'order_id' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'access_id' => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'default' => '0')), array('area_name' => array('fields' => array('area_name'))));
    } catch (\Cx\Lib\UpdateException $e) {
        // we COULD do something else here..
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /*********************
     *
     * ADD COUNTRY TABLE
     *
     ********************/
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'lib_country', array('id' => array('type' => 'INT(11)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(64)', 'after' => 'id'), 'iso_code_2' => array('type' => 'CHAR(2)', 'after' => 'name'), 'iso_code_3' => array('type' => 'CHAR(3)', 'notnull' => false, 'after' => 'iso_code_2')), array('unique' => array('fields' => array('iso_code_2'), 'type' => 'UNIQUE'), 'INDEX_COUNTRIES_NAME' => array('fields' => array('name'))), 'InnoDB');
        $arrCountries = array(1 => array('name' => 'Afghanistan', 'iso_2' => 'AF', 'iso_3' => 'AFG'), 2 => array('name' => 'Albania', 'iso_2' => 'AL', 'iso_3' => 'ALB'), 3 => array('name' => 'Algeria', 'iso_2' => 'DZ', 'iso_3' => 'DZA'), 4 => array('name' => 'American Samoa', 'iso_2' => 'AS', 'iso_3' => 'ASM'), 5 => array('name' => 'Andorra', 'iso_2' => 'AD', 'iso_3' => 'AND'), 6 => array('name' => 'Angola', 'iso_2' => 'AO', 'iso_3' => 'AGO'), 7 => array('name' => 'Anguilla', 'iso_2' => 'AI', 'iso_3' => 'AIA'), 8 => array('name' => 'Antarctica', 'iso_2' => 'AQ', 'iso_3' => 'ATA'), 9 => array('name' => 'Antigua and Barbuda', 'iso_2' => 'AG', 'iso_3' => 'ATG'), 10 => array('name' => 'Argentina', 'iso_2' => 'AR', 'iso_3' => 'ARG'), 11 => array('name' => 'Armenia', 'iso_2' => 'AM', 'iso_3' => 'ARM'), 12 => array('name' => 'Aruba', 'iso_2' => 'AW', 'iso_3' => 'ABW'), 13 => array('name' => 'Australia', 'iso_2' => 'AU', 'iso_3' => 'AUS'), 14 => array('name' => 'Österreich', 'iso_2' => 'AT', 'iso_3' => 'AUT'), 15 => array('name' => 'Azerbaijan', 'iso_2' => 'AZ', 'iso_3' => 'AZE'), 16 => array('name' => 'Bahamas', 'iso_2' => 'BS', 'iso_3' => 'BHS'), 17 => array('name' => 'Bahrain', 'iso_2' => 'BH', 'iso_3' => 'BHR'), 18 => array('name' => 'Bangladesh', 'iso_2' => 'BD', 'iso_3' => 'BGD'), 19 => array('name' => 'Barbados', 'iso_2' => 'BB', 'iso_3' => 'BRB'), 20 => array('name' => 'Belarus', 'iso_2' => 'BY', 'iso_3' => 'BLR'), 21 => array('name' => 'Belgium', 'iso_2' => 'BE', 'iso_3' => 'BEL'), 22 => array('name' => 'Belize', 'iso_2' => 'BZ', 'iso_3' => 'BLZ'), 23 => array('name' => 'Benin', 'iso_2' => 'BJ', 'iso_3' => 'BEN'), 24 => array('name' => 'Bermuda', 'iso_2' => 'BM', 'iso_3' => 'BMU'), 25 => array('name' => 'Bhutan', 'iso_2' => 'BT', 'iso_3' => 'BTN'), 26 => array('name' => 'Bolivia', 'iso_2' => 'BO', 'iso_3' => 'BOL'), 27 => array('name' => 'Bosnia and Herzegowina', 'iso_2' => 'BA', 'iso_3' => 'BIH'), 28 => array('name' => 'Botswana', 'iso_2' => 'BW', 'iso_3' => 'BWA'), 29 => array('name' => 'Bouvet Island', 'iso_2' => 'BV', 'iso_3' => 'BVT'), 30 => array('name' => 'Brazil', 'iso_2' => 'BR', 'iso_3' => 'BRA'), 31 => array('name' => 'British Indian Ocean Territory', 'iso_2' => 'IO', 'iso_3' => 'IOT'), 32 => array('name' => 'Brunei Darussalam', 'iso_2' => 'BN', 'iso_3' => 'BRN'), 33 => array('name' => 'Bulgaria', 'iso_2' => 'BG', 'iso_3' => 'BGR'), 34 => array('name' => 'Burkina Faso', 'iso_2' => 'BF', 'iso_3' => 'BFA'), 35 => array('name' => 'Burundi', 'iso_2' => 'BI', 'iso_3' => 'BDI'), 36 => array('name' => 'Cambodia', 'iso_2' => 'KH', 'iso_3' => 'KHM'), 37 => array('name' => 'Cameroon', 'iso_2' => 'CM', 'iso_3' => 'CMR'), 38 => array('name' => 'Canada', 'iso_2' => 'CA', 'iso_3' => 'CAN'), 39 => array('name' => 'Cape Verde', 'iso_2' => 'CV', 'iso_3' => 'CPV'), 40 => array('name' => 'Cayman Islands', 'iso_2' => 'KY', 'iso_3' => 'CYM'), 41 => array('name' => 'Central African Republic', 'iso_2' => 'CF', 'iso_3' => 'CAF'), 42 => array('name' => 'Chad', 'iso_2' => 'TD', 'iso_3' => 'TCD'), 43 => array('name' => 'Chile', 'iso_2' => 'CL', 'iso_3' => 'CHL'), 44 => array('name' => 'China', 'iso_2' => 'CN', 'iso_3' => 'CHN'), 45 => array('name' => 'Christmas Island', 'iso_2' => 'CX', 'iso_3' => 'CXR'), 46 => array('name' => 'Cocos (Keeling) Islands', 'iso_2' => 'CC', 'iso_3' => 'CCK'), 47 => array('name' => 'Colombia', 'iso_2' => 'CO', 'iso_3' => 'COL'), 48 => array('name' => 'Comoros', 'iso_2' => 'KM', 'iso_3' => 'COM'), 49 => array('name' => 'Congo', 'iso_2' => 'CG', 'iso_3' => 'COG'), 50 => array('name' => 'Cook Islands', 'iso_2' => 'CK', 'iso_3' => 'C*K'), 51 => array('name' => 'Costa Rica', 'iso_2' => 'CR', 'iso_3' => 'CRI'), 52 => array('name' => 'Cote D\'Ivoire', 'iso_2' => 'CI', 'iso_3' => 'CIV'), 53 => array('name' => 'Croatia', 'iso_2' => 'HR', 'iso_3' => 'HRV'), 54 => array('name' => 'Cuba', 'iso_2' => 'CU', 'iso_3' => 'CUB'), 55 => array('name' => 'Cyprus', 'iso_2' => 'CY', 'iso_3' => 'CYP'), 56 => array('name' => 'Czech Republic', 'iso_2' => 'CZ', 'iso_3' => 'CZE'), 57 => array('name' => 'Denmark', 'iso_2' => 'DK', 'iso_3' => 'DNK'), 58 => array('name' => 'Djibouti', 'iso_2' => 'DJ', 'iso_3' => 'DJI'), 59 => array('name' => 'Dominica', 'iso_2' => 'DM', 'iso_3' => 'DMA'), 60 => array('name' => 'Dominican Republic', 'iso_2' => 'DO', 'iso_3' => 'DOM'), 61 => array('name' => 'East Timor', 'iso_2' => 'TP', 'iso_3' => 'TMP'), 62 => array('name' => 'Ecuador', 'iso_2' => 'EC', 'iso_3' => 'ECU'), 63 => array('name' => 'Egypt', 'iso_2' => 'EG', 'iso_3' => 'EGY'), 64 => array('name' => 'El Salvador', 'iso_2' => 'SV', 'iso_3' => 'SLV'), 65 => array('name' => 'Equatorial Guinea', 'iso_2' => 'GQ', 'iso_3' => 'GNQ'), 66 => array('name' => 'Eritrea', 'iso_2' => 'ER', 'iso_3' => 'ERI'), 67 => array('name' => 'Estonia', 'iso_2' => 'EE', 'iso_3' => 'EST'), 68 => array('name' => 'Ethiopia', 'iso_2' => 'ET', 'iso_3' => 'ETH'), 69 => array('name' => 'Falkland Islands (Malvinas)', 'iso_2' => 'FK', 'iso_3' => 'FLK'), 70 => array('name' => 'Faroe Islands', 'iso_2' => 'FO', 'iso_3' => 'FRO'), 71 => array('name' => 'Fiji', 'iso_2' => 'FJ', 'iso_3' => 'FJI'), 72 => array('name' => 'Finland', 'iso_2' => 'FI', 'iso_3' => 'FIN'), 73 => array('name' => 'France', 'iso_2' => 'FR', 'iso_3' => 'FRA'), 74 => array('name' => 'France, Metropolitan', 'iso_2' => 'FX', 'iso_3' => 'FXX'), 75 => array('name' => 'French Guiana', 'iso_2' => 'GF', 'iso_3' => 'GUF'), 76 => array('name' => 'French Polynesia', 'iso_2' => 'PF', 'iso_3' => 'PYF'), 77 => array('name' => 'French Southern Territories', 'iso_2' => 'TF', 'iso_3' => 'ATF'), 78 => array('name' => 'Gabon', 'iso_2' => 'GA', 'iso_3' => 'GAB'), 79 => array('name' => 'Gambia', 'iso_2' => 'GM', 'iso_3' => 'GMB'), 80 => array('name' => 'Georgia', 'iso_2' => 'GE', 'iso_3' => 'GEO'), 81 => array('name' => 'Deutschland', 'iso_2' => 'DE', 'iso_3' => 'DEU'), 82 => array('name' => 'Ghana', 'iso_2' => 'GH', 'iso_3' => 'GHA'), 83 => array('name' => 'Gibraltar', 'iso_2' => 'GI', 'iso_3' => 'GIB'), 84 => array('name' => 'Greece', 'iso_2' => 'GR', 'iso_3' => 'GRC'), 85 => array('name' => 'Greenland', 'iso_2' => 'GL', 'iso_3' => 'GRL'), 86 => array('name' => 'Grenada', 'iso_2' => 'GD', 'iso_3' => 'GRD'), 87 => array('name' => 'Guadeloupe', 'iso_2' => 'GP', 'iso_3' => 'GLP'), 88 => array('name' => 'Guam', 'iso_2' => 'GU', 'iso_3' => 'GUM'), 89 => array('name' => 'Guatemala', 'iso_2' => 'GT', 'iso_3' => 'GTM'), 90 => array('name' => 'Guinea', 'iso_2' => 'GN', 'iso_3' => 'GIN'), 91 => array('name' => 'Guinea-bissau', 'iso_2' => 'GW', 'iso_3' => 'GNB'), 92 => array('name' => 'Guyana', 'iso_2' => 'GY', 'iso_3' => 'GUY'), 93 => array('name' => 'Haiti', 'iso_2' => 'HT', 'iso_3' => 'HTI'), 94 => array('name' => 'Heard and Mc Donald Islands', 'iso_2' => 'HM', 'iso_3' => 'HMD'), 95 => array('name' => 'Honduras', 'iso_2' => 'HN', 'iso_3' => 'HND'), 96 => array('name' => 'Hong Kong', 'iso_2' => 'HK', 'iso_3' => 'HKG'), 97 => array('name' => 'Hungary', 'iso_2' => 'HU', 'iso_3' => 'HUN'), 98 => array('name' => 'Iceland', 'iso_2' => 'IS', 'iso_3' => 'ISL'), 99 => array('name' => 'India', 'iso_2' => 'IN', 'iso_3' => 'IND'), 100 => array('name' => 'Indonesia', 'iso_2' => 'ID', 'iso_3' => 'IDN'), 101 => array('name' => 'Iran (Islamic Republic of)', 'iso_2' => 'IR', 'iso_3' => 'IRN'), 102 => array('name' => 'Iraq', 'iso_2' => 'IQ', 'iso_3' => 'IRQ'), 103 => array('name' => 'Ireland', 'iso_2' => 'IE', 'iso_3' => 'IRL'), 104 => array('name' => 'Israel', 'iso_2' => 'IL', 'iso_3' => 'ISR'), 105 => array('name' => 'Italy', 'iso_2' => 'IT', 'iso_3' => 'ITA'), 106 => array('name' => 'Jamaica', 'iso_2' => 'JM', 'iso_3' => 'JAM'), 107 => array('name' => 'Japan', 'iso_2' => 'JP', 'iso_3' => 'JPN'), 108 => array('name' => 'Jordan', 'iso_2' => 'JO', 'iso_3' => 'JOR'), 109 => array('name' => 'Kazakhstan', 'iso_2' => 'KZ', 'iso_3' => 'KAZ'), 110 => array('name' => 'Kenya', 'iso_2' => 'KE', 'iso_3' => 'KEN'), 111 => array('name' => 'Kiribati', 'iso_2' => 'KI', 'iso_3' => 'KIR'), 112 => array('name' => 'Korea, Democratic People\'s Republic of', 'iso_2' => 'KP', 'iso_3' => 'PRK'), 113 => array('name' => 'Korea, Republic of', 'iso_2' => 'KR', 'iso_3' => 'KOR'), 114 => array('name' => 'Kuwait', 'iso_2' => 'KW', 'iso_3' => 'KWT'), 115 => array('name' => 'Kyrgyzstan', 'iso_2' => 'KG', 'iso_3' => 'KGZ'), 116 => array('name' => 'Lao People\'s Democratic Republic', 'iso_2' => 'LA', 'iso_3' => 'LAO'), 117 => array('name' => 'Latvia', 'iso_2' => 'LV', 'iso_3' => 'LVA'), 118 => array('name' => 'Lebanon', 'iso_2' => 'LB', 'iso_3' => 'LBN'), 119 => array('name' => 'Lesotho', 'iso_2' => 'LS', 'iso_3' => 'LSO'), 120 => array('name' => 'Liberia', 'iso_2' => 'LR', 'iso_3' => 'LBR'), 121 => array('name' => 'Libyan Arab Jamahiriya', 'iso_2' => 'LY', 'iso_3' => 'LBY'), 122 => array('name' => 'Liechtenstein', 'iso_2' => 'LI', 'iso_3' => 'LIE'), 123 => array('name' => 'Lithuania', 'iso_2' => 'LT', 'iso_3' => 'LTU'), 124 => array('name' => 'Luxembourg', 'iso_2' => 'LU', 'iso_3' => 'LUX'), 125 => array('name' => 'Macau', 'iso_2' => 'MO', 'iso_3' => 'MAC'), 126 => array('name' => 'Macedonia, The Former Yugoslav Republic of', 'iso_2' => 'MK', 'iso_3' => 'MKD'), 127 => array('name' => 'Madagascar', 'iso_2' => 'MG', 'iso_3' => 'MDG'), 128 => array('name' => 'Malawi', 'iso_2' => 'MW', 'iso_3' => 'MWI'), 129 => array('name' => 'Malaysia', 'iso_2' => 'MY', 'iso_3' => 'MYS'), 130 => array('name' => 'Maldives', 'iso_2' => 'MV', 'iso_3' => 'MDV'), 131 => array('name' => 'Mali', 'iso_2' => 'ML', 'iso_3' => 'MLI'), 132 => array('name' => 'Malta', 'iso_2' => 'MT', 'iso_3' => 'MLT'), 133 => array('name' => 'Marshall Islands', 'iso_2' => 'MH', 'iso_3' => 'MHL'), 134 => array('name' => 'Martinique', 'iso_2' => 'MQ', 'iso_3' => 'MTQ'), 135 => array('name' => 'Mauritania', 'iso_2' => 'MR', 'iso_3' => 'MRT'), 136 => array('name' => 'Mauritius', 'iso_2' => 'MU', 'iso_3' => 'MUS'), 137 => array('name' => 'Mayotte', 'iso_2' => 'YT', 'iso_3' => 'MYT'), 138 => array('name' => 'Mexico', 'iso_2' => 'MX', 'iso_3' => 'MEX'), 139 => array('name' => 'Micronesia, Federated States of', 'iso_2' => 'FM', 'iso_3' => 'FSM'), 140 => array('name' => 'Moldova, Republic of', 'iso_2' => 'MD', 'iso_3' => 'MDA'), 141 => array('name' => 'Monaco', 'iso_2' => 'MC', 'iso_3' => 'MCO'), 142 => array('name' => 'Mongolia', 'iso_2' => 'MN', 'iso_3' => 'MNG'), 143 => array('name' => 'Montserrat', 'iso_2' => 'MS', 'iso_3' => 'MSR'), 144 => array('name' => 'Morocco', 'iso_2' => 'MA', 'iso_3' => 'MAR'), 145 => array('name' => 'Mozambique', 'iso_2' => 'MZ', 'iso_3' => 'MOZ'), 146 => array('name' => 'Myanmar', 'iso_2' => 'MM', 'iso_3' => 'MMR'), 147 => array('name' => 'Namibia', 'iso_2' => 'NA', 'iso_3' => 'NAM'), 148 => array('name' => 'Nauru', 'iso_2' => 'NR', 'iso_3' => 'NRU'), 149 => array('name' => 'Nepal', 'iso_2' => 'NP', 'iso_3' => 'NPL'), 150 => array('name' => 'Netherlands', 'iso_2' => 'NL', 'iso_3' => 'NLD'), 151 => array('name' => 'Netherlands Antilles', 'iso_2' => 'AN', 'iso_3' => 'ANT'), 152 => array('name' => 'New Caledonia', 'iso_2' => 'NC', 'iso_3' => 'NCL'), 153 => array('name' => 'New Zealand', 'iso_2' => 'NZ', 'iso_3' => 'NZL'), 154 => array('name' => 'Nicaragua', 'iso_2' => 'NI', 'iso_3' => 'NIC'), 155 => array('name' => 'Niger', 'iso_2' => 'NE', 'iso_3' => 'NER'), 156 => array('name' => 'Nigeria', 'iso_2' => 'NG', 'iso_3' => 'NGA'), 157 => array('name' => 'Niue', 'iso_2' => 'NU', 'iso_3' => 'NIU'), 158 => array('name' => 'Norfolk Island', 'iso_2' => 'NF', 'iso_3' => 'NFK'), 159 => array('name' => 'Northern Mariana Islands', 'iso_2' => 'MP', 'iso_3' => 'MNP'), 160 => array('name' => 'Norway', 'iso_2' => 'NO', 'iso_3' => 'NOR'), 161 => array('name' => 'Oman', 'iso_2' => 'OM', 'iso_3' => 'OMN'), 162 => array('name' => 'Pakistan', 'iso_2' => 'PK', 'iso_3' => 'PAK'), 163 => array('name' => 'Palau', 'iso_2' => 'PW', 'iso_3' => 'PLW'), 164 => array('name' => 'Panama', 'iso_2' => 'PA', 'iso_3' => 'PAN'), 165 => array('name' => 'Papua New Guinea', 'iso_2' => 'PG', 'iso_3' => 'PNG'), 166 => array('name' => 'Paraguay', 'iso_2' => 'PY', 'iso_3' => 'PRY'), 167 => array('name' => 'Peru', 'iso_2' => 'PE', 'iso_3' => 'PER'), 168 => array('name' => 'Philippines', 'iso_2' => 'PH', 'iso_3' => 'PHL'), 169 => array('name' => 'Pitcairn', 'iso_2' => 'PN', 'iso_3' => 'PCN'), 170 => array('name' => 'Poland', 'iso_2' => 'PL', 'iso_3' => 'POL'), 171 => array('name' => 'Portugal', 'iso_2' => 'PT', 'iso_3' => 'PRT'), 172 => array('name' => 'Puerto Rico', 'iso_2' => 'PR', 'iso_3' => 'PRI'), 173 => array('name' => 'Qatar', 'iso_2' => 'QA', 'iso_3' => 'QAT'), 174 => array('name' => 'Reunion', 'iso_2' => 'RE', 'iso_3' => 'REU'), 175 => array('name' => 'Romania', 'iso_2' => 'RO', 'iso_3' => 'ROM'), 176 => array('name' => 'Russian Federation', 'iso_2' => 'RU', 'iso_3' => 'RUS'), 177 => array('name' => 'Rwanda', 'iso_2' => 'RW', 'iso_3' => 'RWA'), 178 => array('name' => 'Saint Kitts and Nevis', 'iso_2' => 'KN', 'iso_3' => 'KNA'), 179 => array('name' => 'Saint Lucia', 'iso_2' => 'LC', 'iso_3' => 'LCA'), 180 => array('name' => 'Saint Vincent and the Grenadines', 'iso_2' => 'VC', 'iso_3' => 'VCT'), 181 => array('name' => 'Samoa', 'iso_2' => 'WS', 'iso_3' => 'WSM'), 182 => array('name' => 'San Marino', 'iso_2' => 'SM', 'iso_3' => 'SMR'), 183 => array('name' => 'Sao Tome and Principe', 'iso_2' => 'ST', 'iso_3' => 'STP'), 184 => array('name' => 'Saudi Arabia', 'iso_2' => 'SA', 'iso_3' => 'SAU'), 185 => array('name' => 'Senegal', 'iso_2' => 'SN', 'iso_3' => 'SEN'), 186 => array('name' => 'Seychelles', 'iso_2' => 'SC', 'iso_3' => 'SYC'), 187 => array('name' => 'Sierra Leone', 'iso_2' => 'SL', 'iso_3' => 'SLE'), 188 => array('name' => 'Singapore', 'iso_2' => 'SG', 'iso_3' => 'SGP'), 189 => array('name' => 'Slovakia (Slovak Republic)', 'iso_2' => 'SK', 'iso_3' => 'SVK'), 190 => array('name' => 'Slovenia', 'iso_2' => 'SI', 'iso_3' => 'SVN'), 191 => array('name' => 'Solomon Islands', 'iso_2' => 'SB', 'iso_3' => 'SLB'), 192 => array('name' => 'Somalia', 'iso_2' => 'SO', 'iso_3' => 'SOM'), 193 => array('name' => 'South Africa', 'iso_2' => 'ZA', 'iso_3' => 'ZAF'), 194 => array('name' => 'South Georgia and the South Sandwich Islands', 'iso_2' => 'GS', 'iso_3' => 'SGS'), 195 => array('name' => 'Spain', 'iso_2' => 'ES', 'iso_3' => 'ESP'), 196 => array('name' => 'Sri Lanka', 'iso_2' => 'LK', 'iso_3' => 'LKA'), 197 => array('name' => 'St. Helena', 'iso_2' => 'SH', 'iso_3' => 'SHN'), 198 => array('name' => 'St. Pierre and Miquelon', 'iso_2' => 'PM', 'iso_3' => 'SPM'), 199 => array('name' => 'Sudan', 'iso_2' => 'SD', 'iso_3' => 'SDN'), 200 => array('name' => 'Suriname', 'iso_2' => 'SR', 'iso_3' => 'SUR'), 201 => array('name' => 'Svalbard and Jan Mayen Islands', 'iso_2' => 'SJ', 'iso_3' => 'SJM'), 202 => array('name' => 'Swaziland', 'iso_2' => 'SZ', 'iso_3' => 'SWZ'), 203 => array('name' => 'Sweden', 'iso_2' => 'SE', 'iso_3' => 'SWE'), 204 => array('name' => 'Schweiz', 'iso_2' => 'CH', 'iso_3' => 'CHE'), 205 => array('name' => 'Syrian Arab Republic', 'iso_2' => 'SY', 'iso_3' => 'SYR'), 206 => array('name' => 'Taiwan', 'iso_2' => 'TW', 'iso_3' => 'TWN'), 207 => array('name' => 'Tajikistan', 'iso_2' => 'TJ', 'iso_3' => 'TJK'), 208 => array('name' => 'Tanzania, United Republic of', 'iso_2' => 'TZ', 'iso_3' => 'TZA'), 209 => array('name' => 'Thailand', 'iso_2' => 'TH', 'iso_3' => 'THA'), 210 => array('name' => 'Togo', 'iso_2' => 'TG', 'iso_3' => 'TGO'), 211 => array('name' => 'Tokelau', 'iso_2' => 'TK', 'iso_3' => 'TKL'), 212 => array('name' => 'Tonga', 'iso_2' => 'TO', 'iso_3' => 'TON'), 213 => array('name' => 'Trinidad and Tobago', 'iso_2' => 'TT', 'iso_3' => 'TTO'), 214 => array('name' => 'Tunisia', 'iso_2' => 'TN', 'iso_3' => 'TUN'), 215 => array('name' => 'Turkey', 'iso_2' => 'TR', 'iso_3' => 'TUR'), 216 => array('name' => 'Turkmenistan', 'iso_2' => 'TM', 'iso_3' => 'TKM'), 217 => array('name' => 'Turks and Caicos Islands', 'iso_2' => 'TC', 'iso_3' => 'TCA'), 218 => array('name' => 'Tuvalu', 'iso_2' => 'TV', 'iso_3' => 'TUV'), 219 => array('name' => 'Uganda', 'iso_2' => 'UG', 'iso_3' => 'UGA'), 220 => array('name' => 'Ukraine', 'iso_2' => 'UA', 'iso_3' => 'UKR'), 221 => array('name' => 'United Arab Emirates', 'iso_2' => 'AE', 'iso_3' => 'ARE'), 222 => array('name' => 'United Kingdom', 'iso_2' => 'GB', 'iso_3' => 'GBR'), 223 => array('name' => 'United States', 'iso_2' => 'US', 'iso_3' => 'USA'), 224 => array('name' => 'United States Minor Outlying Islands', 'iso_2' => 'UM', 'iso_3' => 'UMI'), 225 => array('name' => 'Uruguay', 'iso_2' => 'UY', 'iso_3' => 'URY'), 226 => array('name' => 'Uzbekistan', 'iso_2' => 'UZ', 'iso_3' => 'UZB'), 227 => array('name' => 'Vanuatu', 'iso_2' => 'VU', 'iso_3' => 'VUT'), 228 => array('name' => 'Vatican City State (Holy See)', 'iso_2' => 'VA', 'iso_3' => 'VAT'), 229 => array('name' => 'Venezuela', 'iso_2' => 'VE', 'iso_3' => 'VEN'), 230 => array('name' => 'Viet Nam', 'iso_2' => 'VN', 'iso_3' => 'VNM'), 231 => array('name' => 'Virgin Islands (British)', 'iso_2' => 'VG', 'iso_3' => 'VGB'), 232 => array('name' => 'Virgin Islands (U.S.)', 'iso_2' => 'VI', 'iso_3' => 'VIR'), 233 => array('name' => 'Wallis and Futuna Islands', 'iso_2' => 'WF', 'iso_3' => 'WLF'), 234 => array('name' => 'Western Sahara', 'iso_2' => 'EH', 'iso_3' => 'ESH'), 235 => array('name' => 'Yemen', 'iso_2' => 'YE', 'iso_3' => 'YEM'), 236 => array('name' => 'Yugoslavia', 'iso_2' => 'YU', 'iso_3' => 'YUG'), 237 => array('name' => 'Zaire', 'iso_2' => 'ZR', 'iso_3' => 'ZAR'), 238 => array('name' => 'Zambia', 'iso_2' => 'ZM', 'iso_3' => 'ZMB'), 239 => array('name' => 'Zimbabwe', 'iso_2' => 'ZW', 'iso_3' => 'ZWE'));
        foreach ($arrCountries as $countryId => $arrCountry) {
            \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "lib_country` VALUES (" . $countryId . ", '" . addslashes($arrCountry['name']) . "', '" . $arrCountry['iso_2'] . "', '" . $arrCountry['iso_3'] . "') ON DUPLICATE KEY UPDATE `id` = `id`");
        }
    } catch (\Cx\Lib\UpdateException $e) {
        // we COULD do something else here..
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        /**********************************************************
         * NEW IN VERSION 2.1: templates for mobile devices!       *
         ***********************************************************/
        /**********************************************************
         * EXTENSION:    Fallback language and app device template *
         * ADDED:        Contrexx v3.0.0                           *
         ***********************************************************/
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'languages', array('id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'lang' => array('type' => 'VARCHAR(5)', 'notnull' => true, 'default' => '', 'after' => 'id'), 'name' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => '', 'after' => 'lang'), 'charset' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => 'iso-8859-1', 'after' => 'name'), 'themesid' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'charset'), 'print_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'themesid'), 'pdf_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'print_themes_id'), 'frontend' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'pdf_themes_id'), 'backend' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'frontend'), 'is_default' => array('type' => 'SET(\'true\',\'false\')', 'notnull' => true, 'default' => 'false', 'after' => 'backend'), 'mobile_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'is_default'), 'fallback' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'mobile_themes_id'), 'app_themes_id' => array('type' => 'INT(2)', 'after' => 'fallback')), array('lang' => array('fields' => array('lang'), 'type' => 'UNIQUE'), 'defaultstatus' => array('fields' => array('is_default'))));
        \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'languages` SET `app_themes_id` = `themesid` WHERE `app_themes_id` = 0');
        \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'languages` SET `mobile_themes_id` = `themesid` WHERE `mobile_themes_id` = 0');
    } catch (\Cx\Lib\UpdateException $e) {
        // we COULD do something else here..
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        /********************************************************************
         * NEW IN VERSION 3.1.1: no fallback language should be possible
         ********************************************************************/
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'languages', array('id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'lang' => array('type' => 'VARCHAR(5)', 'notnull' => true, 'default' => '', 'after' => 'id'), 'name' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => '', 'after' => 'lang'), 'charset' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => 'iso-8859-1', 'after' => 'name'), 'themesid' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'charset'), 'print_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'themesid'), 'pdf_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'print_themes_id'), 'frontend' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'pdf_themes_id'), 'backend' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'frontend'), 'is_default' => array('type' => 'SET(\'true\',\'false\')', 'notnull' => true, 'default' => 'false', 'after' => 'backend'), 'mobile_themes_id' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'is_default'), 'fallback' => array('type' => 'INT(2)', 'unsigned' => true, 'notnull' => false, 'default' => '0', 'after' => 'mobile_themes_id'), 'app_themes_id' => array('type' => 'INT(2)', 'after' => 'fallback')), array('lang' => array('fields' => array('lang'), 'type' => 'UNIQUE'), 'defaultstatus' => array('fields' => array('is_default')), 'name' => array('fields' => array('name')), 'name_2' => array('fields' => array('name'), 'type' => 'FULLTEXT')));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /**********************************************************
     * Add unique index on theme name. Who needs multiple
     * themes with the same name anyways? Are there people
     * who know the difference between "aaa" and "aaa"? Guess
     * not. It's just useless.
     * NOTE THIS KICKS OUT ALL DUPLICATE DESIGNS WITH THE
     * SAME NAME FROM THE DATABASE. WHICH I CONSIDER A
     * NECCESSARY EVIL.
     **********************************************************/
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'skins', array('id' => array('type' => 'INT(2) UNSIGNED', 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'themesname' => array('type' => 'VARCHAR(50)', 'notnull' => true), 'foldername' => array('type' => 'VARCHAR(50)', 'notnull' => true), 'expert' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '1')), array('theme_unique' => array('fields' => array('themesname'), 'type' => 'UNIQUE', 'force' => true), 'folder_unique' => array('fields' => array('foldername'), 'type' => 'UNIQUE', 'force' => true)));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /***********************************************************
     * EXTENSION:    css class instead of id for auto generated *
     *               submenu in nested navigation               *
     * ADDED:        Contrexx v3.0.0                            *
     ************************************************************/
    function changeNestedNavigationCss($directory)
    {
        if ($handle = opendir($directory)) {
            while (($file = readdir($handle)) !== false) {
                if (!in_array($file, array('.', '..', '.svn'))) {
                    $file = $directory . '/' . $file;
                    if (is_dir($file)) {
                        changeNestedNavigationCss($file);
                    } else {
                        if (substr($file, -4) == '.css') {
                            try {
                                $objFile = new \Cx\Lib\FileSystem\File($file);
                                if (($data = $objFile->getData()) && !empty($data)) {
                                    $objFile->write(preg_replace('/#menu_level_(\\d+)(?!([\\w-_]+))/i', '.menu_level_\\1', $data));
                                }
                            } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                                \DBG::msg($e->getMessage());
                                return false;
                            }
                        }
                    }
                }
            }
            closedir($handle);
        }
    }
    $path = ASCMS_DOCUMENT_ROOT . '/themes';
    foreach (scandir($path) as $theme) {
        if (!in_array($theme, array('.', '..'))) {
            $theme = $path . '/' . $theme;
            $changeNestedNavigationCss = false;
            $navigationFiles = array('navbar.html', 'navbar2.html', 'navbar3.html', 'subnavbar.html', 'subnavbar2.html', 'subnavbar3.html');
            foreach ($navigationFiles as $file) {
                $file = $theme . '/' . $file;
                if (file_exists($file)) {
                    try {
                        $objFile = new \Cx\Lib\FileSystem\File($file);
                        if (($data = $objFile->getData()) && !empty($data)) {
                            if (strpos($data, 'nested_navigation') !== false) {
                                $changeNestedNavigationCss = true;
                            }
                        }
                    } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                        \DBG::msg($e->getMessage());
                    }
                }
            }
            if ($changeNestedNavigationCss) {
                changeNestedNavigationCss($theme);
            }
        }
    }
    /*****************************************
     * EXTENSION:   {JAVASCRIPT} placeholder *
     * ADDED:       Contrexx v2.1.0     *
     *****************************************/
    $path = ASCMS_DOCUMENT_ROOT . '/themes';
    foreach (scandir($path) as $theme) {
        if (!in_array($theme, array('.', '..', '.svn'))) {
            $theme = $path . '/' . $theme;
            $file = $theme . '/index.html';
            if (file_exists($file)) {
                try {
                    $objFile = new \Cx\Lib\FileSystem\File($file);
                    if (($data = $objFile->getData()) && !empty($data)) {
                        if (strpos($data, '{JAVASCRIPT}') === false) {
                            $data = preg_replace('/(\\s*)<\\/head>/ms', "\$1    {JAVASCRIPT}\$1</head>", $data);
                            if ($data) {
                                $objFile->write($data);
                            }
                        }
                    }
                } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                    \DBG::msg($e->getMessage());
                }
            }
        }
    }
    /********************************
     * EXTENSION:   Timezone        *
     * ADDED:       Contrexx v3.0.0 *
     ********************************/
    try {
        \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'log` CHANGE `datetime` `datetime` TIMESTAMP NULL DEFAULT "0000-00-00 00:00:00"');
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /**********************************************************
     * EXTENSION:    Session garbage collector considers now   *
     *               the individual lifetime of each session   *
     *               (needed since remember me is implemented) *
     * ADDED:        Contrexx v3.0.1                           *
     ***********************************************************/
    try {
        $arrColumns = $objDatabase->MetaColumnNames(DBPREFIX . 'sessions');
        if ($arrColumns === false) {
            setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'sessions'));
            return false;
        }
        if (!isset($arrColumns['REMEMBER_ME'])) {
            \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'sessions` ADD `remember_me` INT(1) NOT NULL DEFAULT 0 AFTER `sessionid`');
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /**********************************************************
     * EXTENSION:    Delete old cache class which causes       *
     *               classloader confliction.                  *
     * ADDED:        Contrexx v3.0.1                           *
     ***********************************************************/
    $path = ASCMS_DOCUMENT_ROOT . '/lib/FRAMEWORK/Cache.class.php';
    if (file_exists($path)) {
        if (!\Cx\Lib\FileSystem\FileSystem::delete_file($path)) {
            setUpdateMsg('Die Datei "/lib/FRAMEWORK/Cache.class.php" konnte nicht gelöscht werden. Bitte löschen Sie diese manuell.', 'error');
            setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_UPDATE_TRY_AGAIN'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
            return false;
        }
    }
    /********************************************************
     * EXTENSION:    Add new access id (178) to those groups *
     *               having access to the news (10) or       *
     *               blog (119) module.                      *
     * ADDED:        Contrexx v3.1.0                         *
     ********************************************************/
    try {
        \Cx\Lib\UpdateUtil::sql('
            INSERT INTO `' . DBPREFIX . 'access_group_static_ids` (`access_id`, `group_id`)
            SELECT 178, `group_id` FROM `' . DBPREFIX . 'access_group_static_ids` WHERE (`access_id` = 10) OR (`access_id` = 119) GROUP BY `group_id`
            ON DUPLICATE KEY UPDATE `access_id` = `access_id`
        ');
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        Text::errorHandler();
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        \Cx\Core\Setting\Controller\Setting::errorHandler();
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    /********************************************************
     * EXTENSION:    ADD COMPONENTS TABLE                    *
     * ADDED:        Contrexx v3.1.0                         *
     ********************************************************/
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'component', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(100)', 'after' => 'id'), 'type' => array('type' => 'ENUM(\'core\',\'core_module\',\'module\')', 'after' => 'name')), null, 'InnoDB');
        \Cx\Lib\UpdateUtil::sql("\n            INSERT IGNORE INTO `" . DBPREFIX . "component` (`id`, `name`, `type`) VALUES\n                (70, 'Workbench', 'core_module'),\n                (71, 'FrontendEditing', 'core_module'),\n                (72, 'ContentManager', 'core')\n        ");
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    return true;
}
Exemple #24
0
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos)
 {
     $tup = self::getTemporaryUploadPath($data['submissionId'], $data['fieldId']);
     // in case uploader has been restricted to only allow one single file to be
     // uploaded, we'll have to clean up any previously uploaded files
     if ($data['singlefile']) {
         if (count($fileInfos['originalFileNames'])) {
             // new files have been uploaded -> remove existing files
             $contactUploadDestinationPath = $tup[0] . '/' . $tup[2];
             if ($dh = opendir($contactUploadDestinationPath)) {
                 while (($uploadedFile = readdir($dh)) !== false) {
                     if ($uploadedFile == '..' || $uploadedFile == '.') {
                         continue;
                     }
                     \Cx\Lib\FileSystem\FileSystem::delete_file($contactUploadDestinationPath . '/' . $uploadedFile);
                 }
                 closedir($dh);
             }
         }
         // remove additional files, in case more than one file has been uploaded
         if (count($fileInfos['originalFileNames']) > 1) {
             $firstUploadedFile = array_shift($fileInfos['originalFileNames']);
             if ($dh = opendir($tempPath)) {
                 while (($uploadedFile = readdir($dh)) !== false) {
                     if ($uploadedFile == '..' || $uploadedFile == '.' || $uploadedFile == $firstUploadedFile) {
                         continue;
                     }
                     \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $uploadedFile);
                 }
                 closedir($dh);
             }
         }
     }
     return array($tup[0] . '/' . $tup[2], $tup[1] . '/' . $tup[2]);
 }
 /**
  * delete a file with hash and check code
  *
  * @param string $hash the hash code of the file which should be deleted
  * @param string $check the check code of the file which should be deleted
  * @return bool delete already successful (true), confirmation form is shown (false)
  */
 private function deleteFile($hash, $check)
 {
     global $objDatabase;
     $objResult = $objDatabase->SelectLimit("SELECT `id`, `file`, `source`, `check` FROM " . DBPREFIX . "module_filesharing WHERE `hash` = '" . contrexx_raw2db($hash) . "'", 1, 0);
     if ($objResult === false || $objResult->RecordCount() == 0) {
         // no file exists with this hash
         return true;
     }
     if (!isset($_POST['delete']) && $_POST['delete'] == false) {
         // user didn't yet confirm delete action
         $this->showDeleteConfirmation($objResult->fields);
         return false;
     }
     if ($objResult->fields["check"] == $check) {
         // check whether the check code is the same as in the database
         \Cx\Lib\FileSystem\FileSystem::delete_file(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath() . $objResult->fields["source"]);
         $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_filesharing WHERE `id` = " . intval($objResult->fields["id"]));
     }
     return true;
 }