fork download
  1. <?php
  2.  
  3. class AppController extends Controller{
  4. var $components = Array('SwiftMailer', 'Auth', 'Email', 'Session', 'Facebook.Connect', 'Uploader.Uploader', 'FormKeeper.FormKeeper', 'Recaptcha.Captcha' => array(
  5. 'private_key' => '6LcDt8sSAAAAAEnkcMKDiFX1QtIovebWAH9lUDEm',
  6. 'public_key' => '6LcDt8sSAAAAAHggUKIrTj6zNQx4jkNU0raWlO_Y'),'Cookie');
  7. var $helpers = array('Html','Form','PaypalIpn.Paypal', 'Session', 'Facebook.Facebook', 'FormKeeper.FormKeeper', 'Recaptcha.CaptchaTool');
  8. var $uses = array('Reservation', 'Topic');
  9.  
  10. function beforeFilter(){
  11.  
  12. //$this->set('facebook_user', $this->Connect->user());
  13.  
  14. define('RESERVATION_FEE','.12');
  15. $this->Auth->allow('signup','validateform','create','display');// controller actions unauthenticated users have access too, which then renders the view
  16. $this->Auth->authError = 'You must have an account to view this page. Please sign in or sign up for an account';
  17. $this->Auth->loginError = 'Incorrect username/password combination';
  18. //debug($this->Auth->user());
  19. $this->set('searchbar',0);
  20. if($this->Auth->isAuthorized())
  21. {
  22. $this->set('auth','1');
  23. $messages = $this->Topic->find('count', array('conditions' => array('Topic.viewed' => '0', 'Topic.to_user'=>$this->Auth->user('id'))));
  24. $bookings = $this->Reservation->find('count', array('conditions' => array('Reservation.status' => '1', 'Reservation.host_id'=>$this->Auth->user('id'))));
  25. $this->set('messagesCount', $messages);
  26. $this->set('reservationsCount', $bookings);
  27.  
  28. }
  29. else{
  30. $this->set('auth','0');
  31. }
  32. $this->Auth->loginRedirect = array('controller' => 'messages', 'action' => 'mymessages');
  33.  
  34.  
  35. }
  36.  
  37.  
  38. function afterPaypalNotification($txnId){
  39. //Here is where you can implement code to apply the transaction to your app.
  40. //for example, you could now mark an order as paid, a subscription, or give the user premium access.
  41. //retrieve the transaction using the txnId passed and apply whatever logic your site needs.
  42.  
  43. $transaction = ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->findById($txnId);
  44. $this->log($transaction['InstantPaymentNotification']['id'], 'paypal');
  45.  
  46. //Tip: be sure to check the payment_status is complete because failure transactions
  47. // are also saved to our database for review.
  48.  
  49. if($transaction['InstantPaymentNotification']['payment_status'] == 'Pending' && $transaction['InstantPaymentNotification']['pending_reason'] == 'authorization'){
  50. $reservationId = $transaction['InstantPaymentNotification']['item_number'];
  51. $this->log($reservationId, 'paypal');
  52. $this->Reservation->id = $reservationId;
  53.  
  54. $reservation = $this->Reservation->find('first', array('Reservation.id' => $reservationId));
  55.  
  56. if($transaction['InstantPaymentNotification']['mc_gross'] == $reservation['Reservation']['total_amount']){
  57. $this->Reservation->saveField('status', 1, array('callbacks' => 'false', 'validate' => 'false'));
  58. }else{
  59. $this->Reservation->saveField('status', 4, array('callbacks' => 'false', 'validate' => 'false'));
  60. $this->sendEmail("support@reservationresources.com", "ID# ".$reservationId." Payment amounts don't match!", "payment");
  61. }
  62. $this->sendEmail("harry@reservationresources.com", "PAYMENT NOTIFICATION ".$reservationId, "payment");
  63. }
  64. else {
  65. //Oh no, better look at this transaction to determine what to do; like email a decline letter.
  66. }
  67. }
  68.  
  69. function _PPHttpPost($methodName_, $nvpStr_) {
  70. $this->autoRender = false;
  71. $environment = 'sandbox'; // or 'beta-sandbox' or 'live'
  72. // Set up your API credentials, PayPal end point, and API version.
  73. $API_UserName = urlencode('invoice_api1.reservationresources.com');
  74. $API_Password = urlencode('REQ6BD9BD3BHEZB3');
  75. $API_Signature = urlencode('A9Ewuf-6vQ6w3KC6MRDfkJjmvTFgAeDiXfKaIz4nBx1D5tDvq1cSyvCs');
  76.  
  77. $API_UserName = urlencode('shahru_1322843474_biz_api1.gmail.com');
  78. $API_Password = urlencode('1322843520');
  79. $API_Signature = urlencode('AafdLz1r6EWooI64eLNUccpog7G0AxeVDUzI.vjZ.0BI5Ch0mGLGkfBp');
  80.  
  81. $API_Endpoint = "https://a...content-available-to-author-only...l.com/nvp";
  82. if("sandbox" === $environment || "beta-sandbox" === $environment) {
  83. $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
  84. }
  85. $version = urlencode('51.0');
  86.  
  87. // Set the curl parameters.
  88. $ch = curl_init();
  89. curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
  90. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  91.  
  92. // Turn off the server and peer verification (TrustManager Concept).
  93. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  94. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  95.  
  96. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  97. curl_setopt($ch, CURLOPT_POST, 1);
  98.  
  99. // Set the API operation, version, and API signature in the request.
  100. $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
  101.  
  102. // Set the request as a POST FIELD for curl.
  103. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
  104.  
  105. // Get response from the server.
  106. $httpResponse = curl_exec($ch);
  107.  
  108. if(!$httpResponse) {
  109. exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
  110. }
  111.  
  112. // Extract the response details.
  113. $httpResponseAr = explode("&", $httpResponse);
  114.  
  115. $httpParsedResponseAr = array();
  116. foreach ($httpResponseAr as $i => $value) {
  117. $tmpAr = explode("=", $value);
  118. if(sizeof($tmpAr) > 1) {
  119. $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
  120. }
  121. }
  122.  
  123. if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
  124. exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
  125. }
  126.  
  127. return $httpParsedResponseAr;
  128.  
  129. /* Set request-specific fields.
  130. $authorizationID = urlencode('example_authorization_id');
  131. $amount = urlencode('example_amount');
  132. $currency = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
  133. $completeCodeType = urlencode('Complete'); // or 'NotComplete'
  134. $invoiceID = urlencode('example_invoice_id');
  135. $note = urlencode('example_note');
  136.  
  137. // Add request-specific fields to the request string.
  138. $nvpStr="&AUTHORIZATIONID=$authorizationID&AMT=$amount&COMPLETETYPE=$completeCodeType&CURRENCYCODE=$currency&NOTE=$note";
  139.  
  140. // Execute the API operation; see the PPHttpPost function above.
  141. $httpParsedResponseAr = PPHttpPost('DoCapture', $nvpStr);
  142.  
  143. if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
  144. exit('Capture Completed Successfully: '.print_r($httpParsedResponseAr, true));
  145. } else {
  146. exit('DoCapture failed: ' . print_r($httpParsedResponseAr, true));
  147. }
  148. */
  149. }
  150.  
  151.  
  152. function deleteimage($name = null, $property = null){//pick up here image handling 11/29/11
  153. $this->autoRender = false;
  154.  
  155. if($this->Uploader->delete('user_photos/'.$this->Auth->user('id').'/'.$property.'/'.$name)&&$this->Uploader->delete('user_photos/'.$this->Auth->user('id').'/'.$property.'/resized/'.$name)){
  156. return true;
  157.  
  158. }
  159. else{
  160. return false;
  161. }
  162.  
  163.  
  164. }
  165. /*
  166. the following 2 functions adds images to a property.
  167. the reason why i had to create 2 functions is becuase they array come in diffrently
  168. based upon if there adding images for the first time or just adding new images to an already
  169. existing property
  170. */
  171. function uploadpropertypics($id = null){
  172.  
  173. $this->autoRender = false;
  174. $folder = new Folder('user_photos/'.DS.$this->Auth->user('id').DS.$id,true);
  175. $resized = new Folder('user_photos/'.DS.$this->Auth->user('id').DS.$id.DS.'resized',true);
  176. $this->Uploader->uploadDir = '/user_photos'.DS.$this->Auth->user('id').DS.$id.'/';
  177.  
  178. for($i = 1; $i < count($this->data['Images']);$i++){
  179. //debug(count($this->data['Images']));
  180. //debug($this->Uploader->tempDir);
  181. if ($data = $this->Uploader->upload('Images.file'.$i)){
  182.  
  183. $scale = $this->Uploader->resize(array('width' => 890, 'append' => 'scaled','quality'=>100));
  184. $this->Uploader->move($scale, 'user_photos/'.$this->Auth->user('id').'/'.$id.'/resized/'.$data['name'],false);
  185. }
  186.  
  187. }
  188.  
  189. }
  190.  
  191. $this->redirect(array('controller' => 'properties', 'action' => 'viewproperty',$id));
  192.  
  193. function addphotos($id = null,$path = null){
  194.  
  195. $this->autoRender = false;
  196. $folder = new Folder('user_photos/'.DS.$this->Auth->user('id').DS.$id,true);
  197. $resized = new Folder('user_photos/'.DS.$this->Auth->user('id').DS.$id.DS.'resized',true);
  198. $this->Uploader->uploadDir = $path;
  199.  
  200.  
  201.  
  202. for($i = 1; $i < count($this->data['Images']);$i++){
  203.  
  204.  
  205. if ($data = $this->Uploader->upload('file'.$i)) {
  206. $scale = $this->Uploader->scale(array('width' => 890, 'append' => 'scaled'));
  207.  
  208. $this->Uploader->move($scale, 'user_photos/'.DS.$this->Auth->user('id').DS.$id.'/resized/'.$data['name'],false);
  209.  
  210. }
  211.  
  212. }
  213.  
  214. }
  215.  
  216. function cleanString($msg = NULL)
  217. {
  218. preg_match("/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i", $msg, $matches);
  219. if(!empty($matches))
  220. return false;
  221. $msg = preg_replace( "/[^a-zA-Z0-9]/i", "", $msg);
  222. $msg = strip_tags($msg);
  223. $unclean = "";
  224.  
  225. $k = 0;
  226. for($i = 0; $i < strlen($msg); $i++)
  227. {
  228. if($k<7)
  229. {
  230. $k = 0;
  231. if(is_numeric(substr($msg, $i, 1)))
  232. {
  233. for($j = $i; $j < strlen($msg); $j++)
  234. {
  235. if(is_numeric(substr($msg, $j, 1)))
  236. {
  237. $k++;
  238. }
  239. else
  240. $k = 0;
  241.  
  242. $i = $j;
  243. //Pushes the larger for loop to continue where this one left off after checking numbers in a row
  244. }
  245.  
  246. }
  247. }
  248. else
  249. $i = strlen($msg);
  250.  
  251. }
  252.  
  253. if($k<7)
  254. return true;
  255. else
  256. return false; //UNCLEAN STRING
  257. }
  258.  
  259.  
  260. function sendEmail($email, $subject, $layout) {
  261. /*$this->Email->reset();
  262.   $this->Email->to = $email;
  263.   $this->Email->subject = $subject;
  264.   $this->Email->replyTo = 'support@reservationresources.com';
  265.   $this->Email->from = 'Reservation Resources <noreply@reservationresources.com>';
  266. //debug($this->Email);
  267.   $this->Email->template = $layout; // note no '.ctp'
  268.   //Send as 'html', 'text' or 'both' (default is 'text')
  269.   $this->Email->sendAs = 'html'; // because we like to send pretty mail
  270.   //Do not pass any args to send()
  271.   $this->Email->send();
  272.  
  273. ONLY WORKS FOR ONE EMAIL FOR SOME REASON
  274. */
  275. //Function is copy + pasted in Profiles / verify && Users / forgotpassword && Harries/sendEmail
  276. $this->SwiftMailer->smtpType = 'tls';
  277. $this->SwiftMailer->smtpHost = 'smtp.gmail.com';
  278. $this->SwiftMailer->smtpPort = 587;
  279. $this->SwiftMailer->smtpUsername = 'support@reservationresources.com';
  280. $this->SwiftMailer->smtpPassword = 'hARRY1234%^';
  281.  
  282. $this->SwiftMailer->sendAs = 'html';
  283. $this->SwiftMailer->from = 'support@reservationresources.com';
  284. $this->SwiftMailer->fromName = 'Support Team';
  285. $this->SwiftMailer->to = $email;
  286. //set variables to template as usual
  287. try {
  288. if(!$this->SwiftMailer->send($layout, $subject)) {
  289. $this->log("Error sending email");
  290. }
  291. }
  292. catch(Exception $e) {
  293. $this->log("Failed to send email: ".$e->getMessage());
  294. }
  295.  
  296. }
  297.  
  298. }
  299. ?>
Runtime error #stdin #stdout 0.02s 13664KB
stdin
Standard input is empty
stdout
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/vK0Ufw/prog.php on line 191