Esempio n. 1
0
 function render()
 {
     # Make sure the result is set to 'not submitted' per default
     $result = new Dto_FormResult('notsubmitted');
     # Validate proper permissions
     if ($this->_userIdToEdit == $this->_currentSession['user']['userid']) {
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_own_userprefs, '');
     } else {
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_other_users, '');
     }
     # if
     # Instantiate the user system as necessary for the management of user preferences
     $svcUserRecord = new Services_User_Record($this->_daoFactory, $this->_settings);
     # set the page title
     $this->_pageTitle = "spot: edit user preferences";
     # retrieve the to-edit user
     $spotUser = $svcUserRecord->getUser($this->_userIdToEdit);
     if ($spotUser === false) {
         $result->addError(sprintf(_('User %d can not be found'), $this->_userIdToEdit));
     }
     # if
     /*
      * bring the forms' action into the local scope for
      * easier access
      */
     $formAction = $this->_editUserPrefsForm['action'];
     /*
      * Check to see if a file was uploaded, if so, handle any associated errors
      */
     $avatarFileName = '';
     if ($formAction == 'edit') {
         $uploadHandler = new Services_Providers_FileUpload('edituserprefsform', 'avatar');
         if ($uploadHandler->isUploaded()) {
             if (!$uploadHandler->success()) {
                 $result->addError(_('Unable to update avatar') . '(' . $uploadHandler->errorText() . ')');
             } else {
                 $avatarFileName = $uploadHandler->getTempName();
             }
             # else
         }
         # if
     }
     # if
     # Are we trying to submit this form, or only rendering it?
     if (!empty($formAction) && !$result->isError()) {
         switch ($formAction) {
             case 'edit':
                 $svcActn_EditUserPrefs = new Services_Actions_EditUserPrefs($this->_daoFactory, $this->_settings, $this->_spotSec);
                 $result = $svcActn_EditUserPrefs->editUserPref($this->_editUserPrefsForm, $this->_tplHelper->getTemplatePreferences(), $spotUser, $avatarFileName);
                 break;
                 # case 'edit'
             # case 'edit'
             case 'cancel':
                 $result->setResult('success');
                 # case 'cancel'
         }
         # switch
     }
     # if
     #- display stuff -#
     $this->template('edituserprefs', array('edituserprefsform' => $spotUser['prefs'], 'spotuser' => $spotUser, 'dialogembedded' => $this->_dialogembedded, 'http_referer' => $this->_editUserPrefsForm['http_referer'], 'result' => $result));
 }
Esempio n. 2
0
 function render()
 {
     $result = new Dto_FormResult('notsubmitted');
     # Make sure the user has the appropriate rights
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_keep_own_filters, '');
     # Instantiate the SpotUser system
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $spotFilter = $svcUserFilter->getFilter($this->_currentSession['user']['userid'], $this->_filterId);
     # set the page title
     $this->_pageTitle = "spot: filters";
     /*
      * bring the forms' action into the local scope for 
      * easier access
      */
     $formAction = $this->_editFilterForm['action'];
     # Are we submitting this form, or just rendering it?
     if (!empty($formAction)) {
         switch ($formAction) {
             case 'removefilter':
                 $result = $svcUserFilter->removeFilter($this->_currentSession['user']['userid'], $this->_filterId);
                 break;
                 # case 'removefilter'
             # case 'removefilter'
             case 'discardfilters':
                 $result = $svcUserFilter->resetFilterList($this->_currentSession['user']['userid']);
                 break;
                 # case 'discardfilters'
             # case 'discardfilters'
             case 'setfiltersasdefault':
                 $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_set_filters_as_default, '');
                 $result = $svcUserFilter->setFiltersAsDefault($this->_currentSession['user']['userid']);
                 break;
                 # case 'setfiltersasdefault'
             # case 'setfiltersasdefault'
             case 'exportfilters':
                 $result = $svcUserFilter->filtersToXml($svcUserFilter->getPlainFilterList($this->_currentSession['user']['userid'], 'filter'));
                 break;
                 # case 'exportfilters'
             # case 'exportfilters'
             case 'importfilters':
                 $uploadHandler = new Services_Providers_FileUpload('editfilterform', 'filterimport');
                 if ($uploadHandler->isUploaded()) {
                     if ($uploadHandler->success()) {
                         try {
                             $xml = file_get_contents($uploadHandler->getTempName());
                             $filterList = $svcUserFilter->xmlToFilters($xml);
                             $svcUserFilter->setFilterList($this->_currentSession['user']['userid'], $filterList->getData('filters'));
                         } catch (Exception $x) {
                             $result->addError(_('Uploaded Spotwebfilter in invalid'));
                         }
                         # catch
                     } else {
                         $result->addError(sprintf(_('Error while uploading filter (%s)', $uploadHandler->errorText())));
                     }
                     # else
                 } else {
                     $result->addError(_("Filter hasn't been uploaded"));
                 }
                 # else
                 break;
                 # case 'importfilters'
             # case 'importfilters'
             case 'addfilter':
                 # Create a new filter record, we will always add the filter to the root with no children
                 $filter = $this->_editFilterForm;
                 $filter['valuelist'] = explode('&', $filter['valuelist']);
                 $filter['torder'] = 999;
                 $filter['tparent'] = 0;
                 $filter['children'] = array();
                 $filter['filtertype'] = 'filter';
                 $filter['enablenotify'] = isset($filter['enablenotify']) ? true : false;
                 # and actually add the filter
                 $result = $svcUserFilter->addFilter($this->_currentSession['user']['userid'], $filter);
                 break;
                 # case 'addfilter'
             # case 'addfilter'
             case 'reorder':
                 /*
                  * The nestedSortable jquery widget will not pass an explicit sorting, we
                  * add it ourselves using the order of the elements we are given
                  */
                 $result = $svcUserFilter->reorderFilters($this->_currentSession['user']['userid'], $this->_orderList);
                 break;
                 # case 'reorder'
             # case 'reorder'
             case 'changefilter':
                 # Retrieve the filter we want to edit
                 $this->_editFilterForm['id'] = $this->_filterId;
                 $this->_editFilterForm['enablenotify'] = isset($this->_editFilterForm['enablenotify']) ? true : false;
                 $result = $svcUserFilter->changeFilter($this->_currentSession['user']['userid'], $this->_editFilterForm);
                 break;
                 # case 'changefilter'
         }
         # switch
     }
     # if
     #- display stuff -#
     $this->template('editfilter', array('filter' => $spotFilter, 'sorton' => $this->_sorton, 'sortorder' => $this->_sortorder, 'sortby' => $this->_sorton, 'sortdir' => $this->_sortorder, 'lastformaction' => $formAction, 'result' => $result, 'data' => $this->_data, 'http_referer' => $this->_editFilterForm['http_referer']));
 }
Esempio n. 3
0
 function render()
 {
     # Make sure the result is set to 'not comited' per default
     $result = new Dto_FormResult('notsubmitted');
     # Validate proper permissions
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_post_spot, '');
     # Sportparser is nodig voor het escapen van de random string
     $spotParseUtil = new Services_Format_Util();
     # we need the spotuser system
     $svcUserRecord = new Services_User_Record($this->_daoFactory, $this->_settings);
     /*
      * Create a default form so we can be sure to always be able
      * to render the form without notices or whatever
      */
     $spot = array('title' => '', 'body' => '', 'category' => 0, 'subcata' => '', 'subcatb' => array(), 'subcatc' => array(), 'subcatd' => array(), 'subcatz' => '', 'tag' => '', 'website' => '', 'newmessageid' => '', 'randomstr' => '');
     /* 
      * bring the forms' action into the local scope for 
      * easier access
      */
     $formAction = $this->_spotForm['action'];
     # set the page title
     $this->_pageTitle = "spot: post";
     # Make sure all variables are merged with the default form
     $spot = array_merge($spot, $this->_spotForm);
     # If user tried to submit, validate the file uploads
     $nzbFilename = '';
     $imgFilename = '';
     if ($formAction == 'post') {
         $result->setResult('success');
         # Make sure an NZB file was provided
         $uploadHandler = new Services_Providers_FileUpload('newspotform', 'nzbfile');
         if (!$uploadHandler->isUploaded()) {
             $result->addError(_('Please select NZB file'));
         } elseif (!$uploadHandler->success()) {
             $result->addError(_('Invalid NZB file') . ' (' . $uploadHandler->errorText() . ')');
         } else {
             $nzbFilename = $uploadHandler->getTempName();
         }
         # if
         # Make sure an picture was provided
         $uploadHandler = new Services_Providers_FileUpload('newspotform', 'imagefile');
         if (!$uploadHandler->isUploaded()) {
             $result->addError(_('Please select a picture'));
         } elseif (!$uploadHandler->success()) {
             $result->addError(_('Invalid picture') . ' (' . $uploadHandler->errorText() . ')');
         } else {
             $imgFilename = $uploadHandler->getTempName();
         }
         # if
     }
     # if
     if ($formAction == 'post' && $result->isSuccess()) {
         # Initialize notificatiesystem
         $spotsNotifications = new SpotNotifications($this->_daoFactory, $this->_settings, $this->_currentSession);
         # Make sure we can post this spot, if so, make it happen
         $svcPostSpot = new Services_Posting_Spot($this->_daoFactory, $this->_settings);
         $result = $svcPostSpot->postSpot($svcUserRecord, $this->_currentSession['user'], $spot, $imgFilename, $nzbFilename);
         if ($result->isSuccess()) {
             $result->addData('user', $this->_currentSession['user']['username']);
             $result->addData('spotterid', $spotParseUtil->calculateSpotterId($this->_currentSession['user']['publickey']['modulo']));
             # en send a notification
             $spotsNotifications->sendSpotPosted($spot);
         }
         # if
     }
     # if
     #- display stuff -#
     $this->template('newspot', array('postspotform' => $spot, 'result' => $result));
 }