Advertisement
Evolutio

Untitled

Nov 9th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. <?php
  2. require_once(WCF_DIR.'lib/form/CaptchaForm.class.php');
  3. require_once(WCF_DIR.'lib/data/user/User.class.php');
  4. require_once(WCF_DIR.'lib/page/util/menu/HeaderMenu.class.php');
  5. require_once(WCF_DIR.'lib/page/util/InlineCalendar.class.php');
  6. require_once(WCF_DIR.'lib/data/user/rank/UserRank.class.php');
  7. require_once(WCF_DIR.'lib/data/user/UserProfile.class.php');
  8. /**
  9.  * Form for adding a Donation.
  10.  *
  11.  * @author  Lars Mehrhoff
  12.  * @license GPLv3 <http://www.gnu.org/licenses/gpl-3.0.txt>
  13.  * @package de.evolutio.paysafecard.donation
  14.  */
  15. class PaysafecardDonationAddForm extends CaptchaForm {
  16.     // template name
  17.     public $templateName = 'paysafecardDonationAdd';
  18.     public $neededPermissions = 'user.paysafecard_donation.canAdd';
  19.    
  20.     public function readFormParameters() {
  21.         parent::readFormParameters();
  22.        
  23.         if (isset($_POST['paysafecardID'])) {
  24.             $this->psc['paysafecardID'] = intval($_POST['paysafecardID']);
  25.         }      
  26.         if (isset($_POST['pin'])) {
  27.             $this->psc['pin'] = intval($_POST['pin']);
  28.         }            
  29.         if (isset($_POST['creator'])) {
  30.             $this->psc['creator'] = StringUtil::trim($_POST['creator']);
  31.         }              
  32.         if (isset($_POST['creatorID'])) {
  33.             $this->psc['creatorID'] = intval($_POST['creatorID']);
  34.         }      
  35.         if (isset($_POST['description'])) {
  36.             $this->psc['description'] = StringUtil::trim($_POST['description']);
  37.         }  
  38.     }
  39.    
  40.     public function validate() {
  41.         parent::validate();
  42.  
  43.         if (empty($this->psc['pin'])) {
  44.             throw new UserInputException('pin', 'empty');
  45.         }
  46.         if (empty($this->psc['description'])) {
  47.             throw new UserInputException('description', 'empty');
  48.         }              
  49.         $this->convertAndValidateDate();
  50.     }
  51.    
  52.     public function save() {
  53.         parent::save();
  54.        
  55.         $sql = "INSERT INTO wcf".WCF_N."_paysafecard
  56.                     (userID, paysafecardID, pin, amount,description
  57.                     )
  58.                 VALUES ('".WCF::getUser()->userID."',
  59.                         '".escapeString($this->psc['paysafecardID'])."',
  60.                         '".escapeString($this->psc['pin'])."',
  61.                         '".escapeString($this->psc['amount'])."',
  62.                         '".escapeString($this->psc['description'])."')";
  63.        
  64.         WCF::getDB()->sendQuery($sql);
  65.  
  66.         $this->saved();
  67.                
  68.         // redirect to ToDoList
  69.         HeaderUtil::redirect('index.php?page=paysafecardDonation'.SID_ARG_2ND_NOT_ENCODED);
  70.         exit;
  71.     }
  72.    
  73.     public function readData() {
  74.         parent::readData();
  75.        
  76.         $sql = "SELECT *
  77.                 FROM wcf".WCF_N."_paysafecard
  78.                 ORDER BY sortOrder ASC";
  79.        
  80.         $result = WCF::getDB()->sendQuery($sql);
  81.    
  82.         // get groupIDs with groupOption isAssignableUser
  83.         $assignableGroupIDs = "0";
  84.         $sql = "SELECT groupOptionValue.groupID
  85.                 FROM wcf".WCF_N."_group_option_value groupOptionValue
  86.                     LEFT JOIN wcf".WCF_N."_group_option groupOption
  87.                         ON (groupOptionValue.optionID = groupOption.optionID)
  88.                 WHERE groupOption.optionName = 'user.todolist.assigments.isAssignableUser'
  89.                     AND groupOptionValue.optionValue = 1";     
  90.         $result = WCF::getDB()->sendQuery($sql);
  91.         while ($row = WCF::getDB()->fetchArray($result)) {
  92.             $assignableGroupIDs .= ",".intval($row['groupID']);
  93.         }    
  94.        
  95.         // query for user to whom a todo can be assigned
  96.         $sql = "SELECT DISTINCT usergroups.userID, user.username
  97.                 FROM wcf".WCF_N."_user_to_groups usergroups
  98.                     LEFT JOIN wcf".WCF_N."_user user
  99.                         ON (user.userID = usergroups.userID)
  100.                 WHERE
  101.                     usergroups.groupID
  102.                 IN
  103.                     ( ".$assignableGroupIDs." )
  104.                 ORDER BY user.username ASC";
  105.         $result = WCF::getDB()->sendQuery($sql);
  106.        
  107.         // empty entry in list -> possibility not to assign a todo to an user
  108.         $this->assignableUsersArray[""] = "";
  109.        
  110.         while ($row = WCF::getDB()->fetchArray($result)) {
  111.           $this->assignableUsersArray[$row['userID']] = $row['username'];
  112.         }          
  113.        
  114.     }
  115. }
  116. ?>
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement