示例#1
0
 public function validateName()
 {
     $input = JFactory::getApplication()->input;
     $componentName = trim(JRequest::getVar('componentName', ''));
     if (preg_match('#([^a-zA-Z0-9_ ])#', $componentName) || empty($componentName) || $componentName == 'elements') {
         echo '0|' . JText::_('RSFP_UNIQUE_NAME_MSG');
         $this->close();
     }
     //on file upload component, check destination
     $componentType = $input->getInt('componentType');
     if ($componentType == 9) {
         $destination = JRequest::getVar('destination');
         $destination = RSFormProHelper::getRelativeUploadPath($destination);
         if (empty($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_MSG');
             $this->close();
         }
         if (!is_dir($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_MSG');
             $this->close();
         }
         if (!is_writable($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_WRITABLE_MSG');
             $this->close();
         }
     }
     $currentComponentId = $input->getInt('currentComponentId');
     $componentId = $input->getInt('componentId');
     $formId = $input->getInt('formId');
     $exists = RSFormProHelper::componentNameExists($componentName, $formId, $currentComponentId);
     if ($exists) {
         echo '0|' . JText::_('RSFP_UNIQUE_NAME_MSG');
     } else {
         echo 'Ok';
     }
     $this->close();
 }
示例#2
0
 /**
  * Validates a component name
  */
 function componentsValidateName()
 {
     $componentName = trim(JRequest::getVar('componentName', ''));
     if (preg_match('#([^a-zA-Z0-9_ ])#', $componentName) || empty($componentName)) {
         echo '0|' . JText::_('RSFP_UNIQUE_NAME_MSG');
         exit;
     }
     //on file upload component, check destination
     $componentType = JRequest::getInt('componentType');
     if ($componentType == 9) {
         $destination = JRequest::getVar('destination');
         if (empty($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_MSG');
             exit;
         }
         if (!is_dir($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_MSG');
             exit;
         }
         if (!is_writable($destination)) {
             echo '2|' . JText::_('RSFP_ERROR_DESTINATION_WRITABLE_MSG');
             exit;
         }
     }
     if ($componentType == 6) {
         $mindate = JRequest::getVar('mindate');
         $maxdate = JRequest::getVar('maxdate');
         if ($mindate && $maxdate && @strtotime($mindate) > @strtotime($maxdate)) {
             echo '2|' . JText::_('RSFP_CALENDAR_DATES_ERROR_MSG');
             exit;
         }
     }
     $currentComponentId = JRequest::getInt('currentComponentId');
     $componentId = JRequest::getInt('componentId');
     $formId = JRequest::getInt('formId');
     $exists = RSFormProHelper::componentNameExists($componentName, $formId, $currentComponentId);
     if ($exists) {
         echo '0|' . JText::_('RSFP_UNIQUE_NAME_MSG');
     } else {
         echo 'Ok';
     }
     exit;
 }
 public static function copyComponent($sourceComponentId, $toFormId)
 {
     $sourceComponentId = (int) $sourceComponentId;
     $toFormId = (int) $toFormId;
     $db = JFactory::getDBO();
     $db->setQuery("SELECT * FROM #__rsform_components WHERE ComponentId='" . $sourceComponentId . "'");
     $component = $db->loadObject();
     if (!$component) {
         return false;
     }
     //get max ordering
     $db->setQuery("SELECT MAX(`Order`)+1 FROM #__rsform_components WHERE FormId = '" . $toFormId . "'");
     $component->Order = $db->loadResult();
     $db->setQuery("INSERT INTO #__rsform_components SET `FormId`='" . $toFormId . "', `ComponentTypeId`='" . $component->ComponentTypeId . "', `Order`='" . $component->Order . "',`Published`='" . $component->Published . "'");
     $db->execute();
     $newComponentId = $db->insertid();
     $db->setQuery("SELECT * FROM #__rsform_properties WHERE ComponentId='" . $sourceComponentId . "'");
     $properties = $db->loadObjectList();
     foreach ($properties as $property) {
         if ($property->PropertyName == 'NAME' && $toFormId == $component->FormId) {
             $property->PropertyValue .= ' copy';
             while (RSFormProHelper::componentNameExists($property->PropertyValue, $toFormId)) {
                 $property->PropertyValue .= mt_rand(0, 9);
             }
         }
         $db->setQuery("INSERT INTO #__rsform_properties SET ComponentId='" . $newComponentId . "', PropertyName='" . $db->escape($property->PropertyName) . "', PropertyValue='" . $db->escape($property->PropertyValue) . "'");
         $db->execute();
     }
     // copy language
     $db->setQuery("SELECT * FROM #__rsform_translations WHERE `reference`='properties' AND `reference_id` LIKE '" . $sourceComponentId . ".%'");
     $translations = $db->loadObjectList();
     foreach ($translations as $translation) {
         $reference_id = $newComponentId . '.' . end(explode('.', $translation->reference_id, 2));
         $db->setQuery("INSERT INTO #__rsform_translations SET `form_id`='" . $toFormId . "', `lang_code`='" . $db->escape($translation->lang_code) . "', `reference`='properties', `reference_id`='" . $db->escape($reference_id) . "', `value`='" . $db->escape($translation->value) . "'");
         $db->execute();
     }
     return $newComponentId;
 }