示例#1
0
 function read_request($options = array())
 {
     $options = array_merge($this->getOptions(), $options);
     if (isset($_POST['list_action']) && $_POST['list_action'] && $options['allow_' . $_POST['list_action']]) {
         $this->action = $_POST['list_action'];
         $action = $this->action . '_set';
         if (method_exists($this, $action)) {
             $count = $this->{$action}($_POST['list_action_id']);
             if (is_numeric($count)) {
                 $message = "{$count} item(s) " . AMP_past_participle($this->action) . ".<BR>";
             } else {
                 $message = $count;
             }
             $this->message = $message;
             if (isset($this->message)) {
                 $flash =& AMP_System_Flash::instance();
                 $flash->add_message($this->message);
             }
         }
     }
 }
示例#2
0
 function commit_import()
 {
     if (!isset($this->_form_import)) {
         $this->_form_import =& $this->_map->getComponent('import');
     }
     if (!$this->_form_import->submitted() || !$this->_form_import->validate()) {
         $this->_form_import->initNoId();
         $this->_form_import->applyDefaults();
         $this->_form_import->Build();
         $this->_display->add($this->_form_import);
         return true;
     }
     $this->_form_import->Build();
     $target_form_id = $this->_form_import->getFormId();
     $import_map = $this->_form_import->getMap();
     $import_file = $this->_form_import->getSource();
     $import_fields = $this->_form_import->getSourceFields();
     if (!$import_file) {
         return false;
     }
     $count = 0;
     // doing this with the UserData structure would be more correct
     // but is too slow to be useful at this time
     //require_once( 'AMP/UserData/Input.inc.php');
     //$user = &new UserDataInput( AMP_Registry::getDbcon( ), $target_form_id, $admin = true );
     //$user->doPlugin( 'QuickForm', 'Build');
     require_once 'AMP/System/User/Profile/Profile.php';
     $user =& new AMP_System_User_Profile(AMP_Registry::getDbcon());
     foreach ($import_file as $row_id => $row_data) {
         $saveable_data = array('modin' => $target_form_id);
         set_time_limit(10);
         foreach ($row_data as $key => $value) {
             $source_key = $import_fields[$key];
             if (!isset($import_map[$source_key])) {
                 continue;
             }
             $saveable_data[$import_map[$source_key]] = $value;
         }
         /*
         if ( isset( $saveable_data['id'])) {
             $user->uid = $saveable_data['id'];
         }
         */
         $user->setData($saveable_data);
         $count += $user->save();
         //$count += $user->doAction( 'Save' );
         //$user->clearData( );
         trigger_error('imported ' . $count);
     }
     $import_action_text = AMP_past_participle(AMP_TEXT_IMPORT);
     if ($count) {
         $this->message(sprintf(AMP_TEXT_LIST_ACTION_SUCCESS, $import_action_text, $count));
     } else {
         $this->message(sprintf(AMP_TEXT_LIST_ACTION_FAIL, $import_action_text));
     }
 }