示例#1
0
 function componentsDuplicate()
 {
     $formId = JRequest::getInt('formId');
     $cids = JRequest::getVar('cid');
     JArrayHelper::toInteger($cids, array());
     foreach ($cids as $cid) {
         RSFormProHelper::copyComponent($cid, $formId);
     }
     $this->setRedirect('index.php?option=com_rsform&task=forms.edit&formId=' . $formId, JText::sprintf('RSFP_COMPONENTS_COPIED', count($cids)));
 }
示例#2
0
 function copy()
 {
     $db = JFactory::getDBO();
     // Get the selected items
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     // Force array elements to be integers
     JArrayHelper::toInteger($cid, array(0));
     $total = 0;
     foreach ($cid as $formId) {
         if (empty($formId)) {
             continue;
         }
         $total++;
         $original =& JTable::getInstance('RSForm_Forms', 'Table');
         $original->load($formId);
         $original->FormName .= ' copy';
         $original->FormTitle .= ' copy';
         $original->FormId = null;
         $copy =& JTable::getInstance('RSForm_Forms', 'Table');
         $copy->bind($original);
         $copy->store();
         $copy->FormLayout = str_replace('rsform_' . $formId . '_page', 'rsform_' . $copy->FormId . '_page', $copy->FormLayout);
         if ($copy->FormLayout != $original->FormLayout) {
             $copy->store();
         }
         $newFormId = $copy->FormId;
         // copy language
         $db->setQuery("SELECT * FROM #__rsform_translations WHERE `reference`='forms' AND `form_id`='" . $formId . "'");
         $translations = $db->loadObjectList();
         foreach ($translations as $translation) {
             $db->setQuery("INSERT INTO #__rsform_translations SET `form_id`='" . $newFormId . "', `lang_code`='" . $db->getEscaped($translation->lang_code) . "', `reference`='forms', `reference_id`='" . $db->getEscaped($translation->reference_id) . "', `value`='" . $db->getEscaped($translation->value) . "'");
             $db->query();
         }
         $componentRelations = array();
         $conditionRelations = array();
         $db->setQuery("SELECT ComponentId FROM #__rsform_components WHERE FormId='" . $formId . "' ORDER BY `Order`");
         $components = $db->loadResultArray();
         foreach ($components as $r) {
             $componentRelations[$r] = RSFormProHelper::copyComponent($r, $newFormId);
         }
         // copy conditions
         $db->setQuery("SELECT * FROM #__rsform_conditions WHERE form_id='" . $formId . "'");
         if ($conditions = $db->loadObjectList()) {
             foreach ($conditions as $condition) {
                 $new_condition =& JTable::getInstance('RSForm_Conditions', 'Table');
                 $new_condition->bind($condition);
                 $new_condition->id = null;
                 $new_condition->form_id = $newFormId;
                 $new_condition->component_id = $componentRelations[$condition->component_id];
                 $new_condition->store();
                 $conditionRelations[$condition->id] = $new_condition->id;
             }
             $db->setQuery("SELECT * FROM #__rsform_condition_details WHERE condition_id IN (" . implode(',', array_keys($conditionRelations)) . ")");
             if ($details = $db->loadObjectList()) {
                 foreach ($details as $detail) {
                     $new_detail =& JTable::getInstance('RSForm_Condition_Details', 'Table');
                     $new_detail->bind($detail);
                     $new_detail->id = null;
                     $new_detail->condition_id = $conditionRelations[$detail->condition_id];
                     $new_detail->component_id = $componentRelations[$detail->component_id];
                     $new_detail->store();
                 }
             }
         }
         // copy post to location
         $db->setQuery("SELECT * FROM #__rsform_posts WHERE form_id='" . $formId . "'");
         if ($post = $db->loadObject()) {
             $db->setQuery("INSERT INTO #__rsform_posts SET `form_id`='" . (int) $newFormId . "', `enabled`='" . (int) $post->enabled . "', `method`='" . (int) $post->method . "', `silent`='" . (int) $post->silent . "', `url`=" . $db->quote($post->url));
             $db->query();
         }
     }
     $this->setRedirect('index.php?option=com_rsform&task=forms.manage', JText::sprintf('RSFP_FORMS_COPIED', $total));
 }