Subversion Repositories SmartDukaan

Rev

Rev 15378 | Rev 15383 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('Controller', 'Controller');
3
 
4
/**
5
 * Application Controller
6
 *
7
 * Add your application-wide methods in the class below, your controllers
8
 * will inherit them.
9
 *
10
 * @package       app.Controller
11
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
12
 */
13
class AppController extends Controller {
13808 anikendra 14
 
15
	public $limit;
16
	public $apihost;
15311 anikendra 17
	public $acls;
13808 anikendra 18
 
13532 anikendra 19
	public $components = array(
14970 anikendra 20
		'Session','Resize','Cookie',
13532 anikendra 21
		'Auth' => array(
22
			'loginAction' => array('controller' => 'users', 'action' => 'login'),
23
			'allowedActions' => array('index', 'view', 'display')
24
		)			
25
	);
13808 anikendra 26
 
13532 anikendra 27
	var $helpers = array('Session', 'Form', 'Html');
28
	var $keywords = array('instagram followers','instagram button','instagram follow back','instagram tool','instagram automation','free istagram followers','instagram stats','instagram follow button');
29
 
30
	function beforeFilter() {
13659 anikendra 31
		$this->Auth->autoRedirect = false;		
13579 anikendra 32
 
33
		//Set config settings according to domain
13532 anikendra 34
		// get host name from URL
35
		preg_match('@^(?:http://)?([^/]+)@i',$_SERVER['HTTP_HOST'], $matches);
36
		$host = $matches[1];
37
		switch($host){			
13567 anikendra 38
			case 'localdtr':
13532 anikendra 39
				Configure::load('dev');
40
				break;
13946 anikendra 41
			case 'staging.profittill.com':
42
			case 'www.staging.profittill.com':
13944 anikendra 43
				Configure::load('staging');
44
				break;
13532 anikendra 45
			default:
13567 anikendra 46
			case 'www.profittill.com':
47
			case 'profittill.com':
13633 anikendra 48
			case 'api.profittill.com':
13532 anikendra 49
				Configure::load('live');
50
				break;
51
		}
13579 anikendra 52
		$facebookConfig = Configure::read("Facebook");		
53
		$categories = Configure::read('Categories');
13532 anikendra 54
		//Facebook configuration
55
		$this->set('fbappid', $facebookConfig['fbappid']);
13579 anikendra 56
		$this->set('apihost', Configure::read('apihost'));
57
 
13532 anikendra 58
	   	$sessionState = $this->Session->read('state');
59
		if(!isset($sessionState)){
60
			$this->Session->write('state' , md5(uniqid(rand(), TRUE))); // CSRF protection
61
		}
62
	 	$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
63
		   . $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/') . "&state="
64
		   . $this->Session->read('state').'&scope=publish_stream,email,user_birthday,publish_actions,user_location';
65
	   	$this->set('dialog_url', $dialog_url);
66
		$this->set('description','Why spend money when you can get something for free');
13579 anikendra 67
		$this->set('categories',$categories);
13532 anikendra 68
		if(isset($this->params['admin'])) {
13739 anikendra 69
			$this->layout = 'admin';
13808 anikendra 70
		}	
71
		$this->apihost = Configure::read('pythonapihost');
72
		$this->limit = Configure::read('dealsperpage');	
13685 anikendra 73
		$staticVersion = Configure::read('staticversion');
74
		$this->set('staticversion',$staticVersion);
14929 anikendra 75
		$this->set('requiremobileverification',Configure::read('requiremobileverification'));			
14970 anikendra 76
		$debugusers = Configure::read('debugusers');
77
		if($id = $this->isAuthorized()){
78
			if(in_array($id, $debugusers)){
79
				$this->Cookie->write('debuguser',1);
80
			}else{
81
				$this->Cookie->delete('debuguser');
82
			}
83
		}
15188 anikendra 84
		//acl
85
		$cachekey = 'acls';
86
		$acls = Cache::read($cachekey,'month');
87
		if(empty($acls)) {
88
			$acls = array();
89
			$this->loadModel('Acl');
90
			$result = $this->Acl->find('all');
91
			foreach ($result as $key => $value) {
92
				if($value['Acl']['access']) {
93
					$acls[$value['Acl']['group_id']]['allowed'][] = $value['Acl']['action'];
94
				}else{
95
					$acls[$value['Acl']['group_id']]['disallowed'][] = $value['Acl']['action'];
96
				}				
97
			}
98
			Cache::write($cachekey,$acls,'month');
99
		}
15311 anikendra 100
		$this->acls = $acls;
15188 anikendra 101
		$this->set('acls',$acls);
13532 anikendra 102
    }
103
 
15311 anikendra 104
	function checkAcl() {		
105
    	if(!in_array($this->here,$this->acls[$this->Session->read('Auth.User.group_id')]['allowed'])){
15227 anikendra 106
    		$this->Session->setFlash(__('You are not authorized to access this page.'));
107
    		return $this->redirect(array('controller'=>'administration','action' => 'dashboard','admin'=>false));
108
    	}
109
    }
110
 
13532 anikendra 111
    function isAuthorized() {
112
        return $this->Auth->user('id');
113
    }
114
 
115
    function isFbAuthorized() {
116
        return $this->Session->read('facebook_id');
117
    }
118
 
119
    function afterFilter() {
13579 anikendra 120
		$result['ucadcode'] = $this->ucadcode;
13532 anikendra 121
    }
122
 
13659 anikendra 123
    function beforeRender() {   
13736 anikendra 124
    	$logged_user = $this->Auth->user();
125
    	$this->set('logged_user', $logged_user); 	
13579 anikendra 126
        $this->set('base_url', 'http://' . $_SERVER['SERVER_NAME'] . Router::url('/'));
13532 anikendra 127
    }
128
 
13736 anikendra 129
    function checkMobileNumber() {
130
    	$logged_user = $this->Auth->user();
131
    	if(empty($logged_user['mobile_verified']) && $this->params['controller'] !='users') {
132
			$skipmobileverification = $this->Session->read('skipmobileverification');
133
			if(!isset($skipmobileverification) || empty($skipmobileverification)) {
134
				$this->redirect('/users/verifymobile');
135
			}
136
		}
137
    }
138
 
15335 anikendra 139
    function checkToken($userId = null) {
140
        $headers =  $this->getallheaders();
14890 anikendra 141
        $this->log(print_r($headers,1),'headers');
14897 anikendra 142
        $token = $_COOKIE['token'];
15188 anikendra 143
        $checkToken = $_COOKIE['walletAuthentication'];
14894 anikendra 144
        $this->log("Token : $token",'headers');
15188 anikendra 145
        $this->log("CheckToken : $checkToken",'headers');
146
        if(isset($checkToken) && !empty($checkToken) && isset($token) && !empty($token)) {
15335 anikendra 147
                $this->loadModel('SocialProfile');
148
                $options = array('conditions'=>array('access_token'=>$token),'fields'=>array('user_id'),'recursive'=>-1);
149
                $user = $this->SocialProfile->find('first',$options);
150
                $this->log(print_r($user['SocialProfile'],1),'headers');
15380 anikendra 151
                /*if(!$userId){
15335 anikendra 152
                	$userId = $this->request->query('user_id');
15380 anikendra 153
                }*/                
15335 anikendra 154
                if(isset($userId) && !empty($userId)){
155
                    if($userId == $user['SocialProfile']['user_id']){
15380 anikendra 156
                    	$this->log("User authenticated",'headers');
15335 anikendra 157
                        return true;
158
                    } else{
159
                    	// token mismatch, so maybe hack attempt
15380 anikendra 160
                    	$this->log("Mismatch hence user not authenticated",'headers');
15335 anikendra 161
                        return false;
162
                    }
163
                } else {
164
                	// userId is not sent so maybe hack attempt
15380 anikendra 165
                	$this->log("Id not sent hence user not authenticated",'headers');
15335 anikendra 166
                	return false;
167
                }
15380 anikendra 168
        } else {    
169
        	$this->log("Old User hence pass",'headers');            
15335 anikendra 170
            return true;
14890 anikendra 171
        }
172
    }
173
 
13659 anikendra 174
    function getallheaders() { 
175
	   $headers = ''; 
176
       foreach ($_SERVER as $name => $value) 
177
       { 
178
	   if (substr($name, 0, 5) == 'HTTP_') 
179
	   { 
180
	       $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
181
	   } 
182
       } 
183
       return $headers; 
184
    } 
13633 anikendra 185
 
15015 anikendra 186
    public function getDealsApiUrl($page=1,$userId = null,$categoryId=0,$sort=null,$direction=null,$filter=null,$brands=null){
13808 anikendra 187
    	$this->log('categoryId '.$categoryId,'api');
188
    	$this->log('page '.$page,'api');
189
    	$offset = ($page - 1) * $this->limit;
190
    	if(isset($sort) && !empty($sort) && $sort!=-1){
191
    		$url = $this->apihost.'deals/'.$userId.'?categoryId='.$categoryId.'&sort='.$sort.'&direction='.$direction.'&limit='.$this->limit.'&offset='.$offset;
192
    	}else{
193
    		$url = $this->apihost.'deals/'.$userId.'?categoryId='.$categoryId.'&limit='.$this->limit.'&offset='.$offset;
194
    	}    	
15015 anikendra 195
    	if(isset($filter) && !empty($filter)){
196
    		$url .= "&filterData=brandFilter:".$brands;
197
    	}
13808 anikendra 198
    	return $url;
199
    }
200
 
13633 anikendra 201
	function make_request($url,$fields,$format='json'){
13683 anikendra 202
		$this->log("[url] $url",'api');
203
		$this->log("[fields] ".print_r($fields,1),'api');
13633 anikendra 204
		$fields_string = '';
205
		//open connection
206
		$ch = curl_init();
207
		//set the url, number of POST vars, POST data
208
		curl_setopt($ch,CURLOPT_URL, $url);
209
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
210
		if(!empty($fields)) {
211
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
212
			curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
213
			    'Content-Type: application/json',                                                                                
13994 anikendra 214
			    // 'Content-Length: ' . sizeof($fields))                                                                       
215
			    'Content-Length: ' . strlen($fields))                                                                       
13633 anikendra 216
			);   
217
		}
218
		//execute post
219
		$result = curl_exec($ch);
15335 anikendra 220
		$this->log("[response] ".print_r($result,1),'api');
13633 anikendra 221
		//close connection
222
		curl_close($ch);
223
		switch($format){
224
			case 'json':
225
			$response = json_decode($result,1);
226
			break;
227
		}
228
		return $response;	
229
	}
13901 anikendra 230
 
14016 anikendra 231
	function post_request($url,$fields,$format='json'){
232
		$this->log("[url] $url",'api');
233
		$this->log("[fields] ".print_r($fields,1),'api');
234
		$fields_string = '';
235
		//open connection
236
		$ch = curl_init();
237
		//execute post
238
		foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
239
		rtrim($fields_string, '&');
240
		//set the url, number of POST vars, POST data
241
		curl_setopt($ch,CURLOPT_URL, $url);
242
		curl_setopt($ch,CURLOPT_POST, count($fields));
243
		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
244
		$result = curl_exec($ch);
245
		$this->log("[response] ".print_r($result,1),'api');
246
		//close connection
247
		curl_close($ch);
248
		switch($format){
249
			case 'json':
250
			$response = json_decode($result,1);
251
			break;
252
		}
253
		return $response;	
254
	}
14215 anikendra 255
 
13901 anikendra 256
	public function get_solr_result($q,$page) {
257
		$dealsperpage = Configure::read('dealsperpage');
258
		$offset = ($page - 1)*$dealsperpage;
13993 anikendra 259
		$cond = "$q";
13901 anikendra 260
	 	$sort = "store desc";
261
 
262
		$params = array(
263
			'conditions' =>array(
264
		 	'solr_query' => $cond
265
	 	),
266
		 	//'order' => $sort,
267
		 	'offset' => $offset,
268
		 	'limit' => $dealsperpage
269
	 	);
14215 anikendra 270
		$this->loadModel('Solr');		
13901 anikendra 271
		$solroutput = $this->Solr->find('all', $params);
272
		$result = array();
14215 anikendra 273
		if(sizeof($solroutput)<$dealsperpage){
274
			$hasMore = false;
275
		}else{
276
			$hasMore = true;
277
		}
13901 anikendra 278
		if(!empty($solroutput['Solr'])) {			
279
			$skuMap = array();
14215 anikendra 280
			foreach ($solroutput['Solr'] as $key => $value) {
14432 anikendra 281
				// if(!$value['in_stock'])continue;
13901 anikendra 282
				$skuMap[$value['id']] = $value;
283
				$result[$value['skuBundleId']][$value['id']] = $value['available_price'];
14215 anikendra 284
			}	
285
			if(!empty($result)) {
286
				foreach ($result as $key => $value) {					
287
					asort($value);
288
					$lowestPriceSku = key($value);
289
					$result[$key] = $skuMap[$lowestPriceSku];
290
				}
13901 anikendra 291
			}
14215 anikendra 292
		}		
293
		$result['hasMore'] = $hasMore;
13901 anikendra 294
		return $result;
295
	}
14098 anikendra 296
 
297
	public function admin_update(){
298
		$this->response->type('json');
299
		$this->layout = 'ajax';
300
		$data[$this->request->data['id']] = $this->request->data['value'];
301
		$data['oid'] = $this->request->data['oid'];
14584 anikendra 302
		$id = $this->request->data['id'];
303
		$multi = $this->request->data['multi'];
14098 anikendra 304
		if($this->modelClass == 'Exceptionalskudiscount') {
305
			$data['class'] = 'SkuDiscountInfo';	
306
		}elseif($this->modelClass == 'Skuscheme'){
14584 anikendra 307
			if($id == 'dp'){
308
				$data['class'] = 'SkuDealerPrices';
309
			}else{
310
				$data['class'] = 'SkuSchemeDetails';
311
			}
14426 anikendra 312
		}elseif($this->modelClass == 'Exceptionalnlc'){
313
			$data['class'] = 'ExceptionalNlc';
314
		}
315
		else{
14098 anikendra 316
			$data['class'] = $this->modelClass;
317
		}		
14584 anikendra 318
		$data_string = json_encode($data,JSON_NUMERIC_CHECK);		
14098 anikendra 319
		$ch = curl_init();
320
		$url = $this->apihost.'Catalog/updateCollection';
14584 anikendra 321
		if(isset($multi) && $multi==1){
322
			$url .= "/?multi=1";
323
		}		
14098 anikendra 324
		$this->log("[url] $url",'api');
325
		$this->log("[fields] ".print_r($data_string,1),'api');
326
		curl_setopt($ch, CURLOPT_URL, $url);
327
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
328
		curl_setopt($ch, CURLOPT_POST, true);
329
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // note the PUT here
330
 
331
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
332
		curl_setopt($ch, CURLOPT_HEADER, true);
333
 
334
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
335
		    'Content-Type: application/json',                                                                                
336
		    'Content-Length: ' . strlen($data_string)                                                                       
337
		));       
338
 
339
		// execute the request
340
 
341
		$output = curl_exec($ch);
342
		$result = $this->request->data['value'];
343
		$this->log("[response] ".print_r($output,1),'api');
344
		curl_close($ch);
345
		$this->set(array(
346
		    'result' => $result,
347
		    '_serialize' => array('result')
348
		));
349
		$this->render('/Elements/json');
350
	}
14150 anikendra 351
 
14509 anikendra 352
	public function remove($id,$class){
353
		$data['oid'] = $id;
354
		$data['class'] = $class;
355
 
356
		$data_string = json_encode($data,JSON_NUMERIC_CHECK);
357
		$ch = curl_init();
358
		$url = $this->apihost.'Catalog/deleteDocument';
359
		$this->log("[url] $url",'api');
360
		$this->log("[fields] ".print_r($data_string,1),'api');
361
		curl_setopt($ch, CURLOPT_URL, $url);
362
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
363
		curl_setopt($ch, CURLOPT_POST, true);
364
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // note the PUT here
365
 
366
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
367
		curl_setopt($ch, CURLOPT_HEADER, true);
368
 
369
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
370
		    'Content-Type: application/json',                                                                                
371
		    'Content-Length: ' . strlen($data_string)                                                                       
372
		));       
373
 
374
		// execute the request
375
 
376
		$output = curl_exec($ch);
377
		$result = $this->request->data['value'];
378
		$this->log("[response] ".print_r($output,1),'api');
379
		curl_close($ch);
380
		// $this->set(array(
381
		    // 'result' => $result,
382
		    // '_serialize' => array('result')
383
		// ));
384
		// $this->render('/Elements/json');
385
		return $result;
386
	}
387
 
14150 anikendra 388
	function getAutoLoginUrl($userId,$next) {
14996 anikendra 389
		$saholicoffline = Configure::read('saholicoffline');
390
		if($saholicoffline) {
391
			$url = "/abouts/saholicoffline";
392
			return $url;
393
		}
14150 anikendra 394
		$this->loadModel('User');
395
		$this->User->Behaviors->attach('Containable');
14166 anikendra 396
		$options = array('contain'=>array('UserAccount'), 'conditions'=>array('User.id'=>$userId),'fields'=>array('username','email'),'recursive'=>-1);
14150 anikendra 397
		$user = $this->User->find('first',$options);
15380 anikendra 398
		$this->log("user_accounts ".print_r($user,1),'headers');
14441 anikendra 399
		$data = array('email'=>$user['User']['email'],'Id'=>$user['UserAccount'][0]['account_key'],'cartId' => $user['UserAccount'][1]['account_key'],'isPrivateDealUser'=>1,'next'=>$next);
14150 anikendra 400
		$data = '?data='.base64_encode(serialize($data));
401
		$token = '&token='.md5(Configure::read('saholicapikey').'|'.$user['UserAccount'][0]['account_key']);		
15335 anikendra 402
		$url = Configure::read('saholicapihost')."login!authorizeProfitMandiUser?userId=".$user['UserAccount'][0]['account_key']."&source=ProfitMandi";
15380 anikendra 403
		$result = $this->make_request($url,null);
404
		$this->log(print_r($result,1),'headers');
15335 anikendra 405
		if(!empty($result['tokenString'])){
406
			$token = '&token='.$result['tokenString'];
407
			return Configure::read('saholicauthurl').$data.$token.'&v=2';
408
		}
14441 anikendra 409
		return Configure::read('saholicauthurl').$data.$token;
14150 anikendra 410
	}
14509 anikendra 411
 
412
 	function createUploadDirectory($modelClass) {
413
        //Create directory
414
        if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {            
415
            $this->log("making directory for $modelClass". WWW_ROOT.DS.'uploads'.DS.$modelClass);
416
            mkdir(WWW_ROOT.'uploads'.DS.$modelClass,0777);
417
        }
418
        if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {
419
            $this->log("failed to create directory for $modelClass");
420
            return false; 
421
        } else {
422
            return true;
423
        }
424
    }
425
 
426
    public function upload() {
427
        $result['status'] = 0; 
428
        $result['success'] = false;
429
        $result['message'] = __('Unable to upload');
430
 
431
        App::import('Vendor','qqFileUploader',array('file' =>'qqFileUploader.php'));
432
 
433
        $uploader = new qqFileUploader();
434
 
435
        // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
436
        $uploader->allowedExtensions = array('jpeg','png','jpg','gif','bmp');
437
 
438
        // Specify max file size in bytes.
439
        $uploader->sizeLimit = 10 * 1024 * 1024;
440
 
441
        // Specify the input name set in the javascript.
442
        $uploader->inputName = 'qqfile';
443
 
444
        // If you want to use resume feature for uploader, specify the folder to save parts.
445
        $uploader->chunksFolder = 'chunks';
446
 
447
        // $min_width = isset($this->request->data['minwidth']) ? $this->request->data['minwidth'] : 0; 
448
        // $min_height = isset($this->request->data['minheight']) ? $this->request->data['minheight'] : 0; 
449
        $modelClass = $this->modelClass; 
450
 
451
        $this->log($this->request);
452
        $folderName = Inflector::pluralize(strtolower($modelClass));
453
 
454
        if (!$this->createUploadDirectory($folderName)) {
455
            $result['message'] = 'Failed to create directory :'.$modelClass.
456
            '.  Sorry we are having trouble.  Please try again, or email help@profittill.com';
457
        } else {
458
            // To save the upload with a specified name, set the second parameter
459
            $result = $uploader->handleUpload('uploads'.DS.$folderName.DS, $uploader->getName());
460
            if($result){
461
                //Resize and create thumbnail
462
                $inFile = WWW_ROOT.'uploads'.DS.$folderName.DS. $uploader->getName();
463
 
464
                $largeOutFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'large-'.basename($inFile);
465
                $this->resizeImage($inFile,$largeOutFile,800,800);
466
 
467
                $outFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'small-'.basename($inFile);
468
                $this->resizeImage($inFile,$outFile,200,200);
469
 
470
                $newUrl = '/uploads/'.$folderName.'/'.basename($inFile);
471
                // To return a name used for uploaded file you can use the following line.
472
                $result['uploadName'] = $newUrl;
473
 
474
                $result['status'] = 1;
475
                $result['success'] = true;
476
                // $result['filesize'] = $filesize;
477
                $result['message'] = __('Uploaded');
478
            }
479
        }
480
        $this->log($result);
481
        return new CakeResponse(array('body' => json_encode($result)));
482
    }
483
 
484
    function cropImage ($url, $height, $width, $x1, $x2, $y1, $y2) {
485
        ini_set('memory_limit', '2G');
486
        $result['status'] = 0; 
487
        $result['message'] = __('Unable to crop');
488
 
489
        $image_type = substr($url, strrpos($url, '.', -1)); 
490
        $filepath = WWW_ROOT.substr($url, strlen(FULL_BASE_URL)+1);
491
        $croppedfile = substr($filepath, 0, strrpos($filepath, '/', -1)).
492
            '/C_'.substr($filepath, strrpos($filepath, '/', -1)+1);
493
 
494
        // Create image instances
495
        $dest = imagecreatetruecolor($x2,$y2);
496
 
497
        switch ($image_type) {
498
            case '.jpg':
499
            case '.jpeg':
500
            case '.JPEG':
501
            case '.JPG':
502
                $src = imagecreatefromjpeg($filepath);
503
                imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
504
                imagejpeg($dest, $croppedfile);
505
                $ext = '.jpg';
506
                break;
507
            case '.gif':
508
                $src = imagecreatefromgif($filepath);
509
                imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
510
                imagegif($dest, $croppedfile);
511
                $ext = '.gif';
512
                break;
513
            case '.png':
514
                $src = imagecreatefrompng($filepath);
515
                imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
516
                imagepng($dest, $croppedfile);
517
                $ext = '.png';
518
                break;
519
            default: 
520
                $result['message'] = __('Unsupported image format.');   
521
                return $result;
522
        }
523
        $result['status'] = 1; 
524
        $result['message'] = __('Cropped');
525
        $result['data'] = substr($url, 0, strrpos($url, '/', -1)).'/C_'.substr($url, strrpos($url, '/', -1)+1);
526
        return $result;
527
    }
528
 
529
    function resizeImage ($inFile, $outFile, $w, $h) {
530
        $image = $this->Resize;
531
        $image->load($inFile);                       
532
        $image->crop($w,$h);
533
        $image->save($outFile);
534
    }
535
 
536
    public function crop() {
537
        $url = $this->request->data['file_url'];
538
        $height = $this->request->data['h']; 
539
        $width = $this->request->data['w']; 
540
        $x1 = $this->request->data['x'];
541
        $x2 = $this->request->data['x2'];
542
        $y1 = $this->request->data['y'];
543
        $y2 = $this->request->data['y2'];
544
 
545
        $result = $this->cropImage($url, $height, $width, $x1, $x2, $y1, $y2);
546
 
547
        $this->set('result', $result);
548
        $this->set('_serialize', array('result'));
549
    }
14561 anikendra 550
 
551
    public function generateMultiUrl($url,&$data){
552
    	if(!empty($data['multi']) && $data['multi']==1){
553
    		$url .= '/?multi=1';    		
554
    	}
555
    	unset($data['multi']);
556
    	return $url;
557
    }
15378 anikendra 558
 
559
    public function markUserActivated($id){
560
    	$url = Configure::read('pythonapihost').'/retailerActivated/'.$id;
561
    	$this->make_request($url,null);
562
    	$this->loadModel('User');
563
    	$sql = "UPDATE users SET activation_time = NOW() WHERE id = $id";
564
    	$this->User->sql($sql);
565
    }
13532 anikendra 566
}