Beispiel #1
0
 function form_field_delete()
 {
     $data = $this->_wysija_form_get_data();
     // check for field_id parameter
     if (isset($data['field_id']) && (int) $data['field_id'] > 0) {
         // get custom field by id
         $custom_field = WJ_Field::get($data['field_id']);
         // if the custom field exists
         if ($custom_field !== null) {
             // we need to remove the field in any form
             // get all forms
             $model_forms = WYSIJA::get('forms', 'model');
             $forms = $model_forms->getRows();
             // get custom field name
             $field_name = $custom_field->user_column_name();
             if (is_array($forms) && count($forms) > 0) {
                 // loop through each form
                 foreach ($forms as $i => $form) {
                     $requires_update = false;
                     // decode form data
                     $data = unserialize(base64_decode($form['data']));
                     // loop through each block
                     foreach ($data['body'] as $j => $block) {
                         // in case we find a text block
                         if ($block['field'] === $field_name) {
                             unset($data['body'][$j]);
                             // flag form to be updated
                             $requires_update = true;
                         }
                     }
                     // if the form requires update, let's do it
                     if ($requires_update === true) {
                         $model_forms->reset();
                         $model_forms->update(array('data' => base64_encode(serialize($data))), array('form_id' => (int) $form['form_id']));
                     }
                 }
             }
             // delete custom field
             $custom_field->delete();
         }
     }
 }
Beispiel #2
0
 public function set($args)
 {
     $this->user_id = $args['user_id'];
     $this->field = WJ_Field::get($args['field_id']);
 }
Beispiel #3
0
 function form_widget_settings()
 {
     $this->iframeTabs = array('form_widget_settings' => __('Widget Settings', WYSIJA));
     $this->js[] = 'wysija-admin-ajax';
     $this->js[] = 'wysija-base-script-64';
     $this->js[] = 'wysija-scriptaculous';
     $_GET['tab'] = 'form_widget_settings';
     // if there is a field id, let's get all that from this field
     if (isset($_REQUEST['field_id'])) {
         $field_id = (int) $_REQUEST['field_id'] > 0 ? (int) $_REQUEST['field_id'] : 0;
         // if the id is positive then try to fetch field data
         $custom_field = WJ_Field::get($field_id);
         // if field has been found
         if ($custom_field !== NULL) {
             $this->data['name'] = isset($_REQUEST['name']) ? $_REQUEST['name'] : $custom_field->name;
             $this->data['type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : $custom_field->type;
             $this->data['field'] = $custom_field->user_column_name();
             $this->data['params'] = $custom_field->settings;
         } else {
             $this->data['name'] = isset($_REQUEST['name']) ? $_REQUEST['name'] : null;
             $this->data['type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
             $this->data['field'] = null;
             $this->data['params'] = null;
         }
         $this->data['field_id'] = $field_id;
     } else {
         // extract parameters from url
         $params = array();
         if (isset($_REQUEST['params']) && trim(strlen($_REQUEST['params'])) > 0) {
             $pairs = explode('|', $_REQUEST['params']);
             if (count($pairs) > 0) {
                 foreach ($pairs as $pair) {
                     // extract both key and value
                     list($key, $value) = explode(':', $pair);
                     // decode value
                     $value = base64_decode($value);
                     // unserialize if necessary (using is_serialized from WordPress)
                     if (is_serialized($value) === true) {
                         $value = unserialize($value);
                     }
                     $params[$key] = $value;
                 }
             }
         }
         // common widget data
         $this->data['name'] = isset($_REQUEST['name']) ? $_REQUEST['name'] : null;
         $this->data['type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
         $this->data['field'] = isset($_REQUEST['field']) ? $_REQUEST['field'] : null;
         // widget params
         $this->data['params'] = $params;
         // extra data that needs to be fetched for some widget
         $extra = array();
         switch ($this->data['type']) {
             // in case of the list widget, we need to pass an array of all available lists
             case 'list':
                 $model_list = WYSIJA::get('list', 'model');
                 // get lists users can subscribe to (aka "enabled list")
                 $extra['lists'] = $model_list->get(array('name', 'list_id', 'is_public'), array('is_enabled' => 1));
                 break;
         }
         $this->data['extra'] = $extra;
     }
     return $this->popupContent();
     exit;
 }