PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/app/controllers/creativezones_controller.php

https://bitbucket.org/fxrialab/spsp_editor
PHP | 1050 lines | 812 code | 207 blank | 31 comment | 124 complexity | e4866a7d3f3e4f7e2da8a492ea1adfdc MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?
  2. class CreativezonesController extends AppController {
  3. var $name='Creativezones';
  4. var $helpers = array('Html','javascript','Ajax');
  5. var $uses=array('Creativezone');
  6. var $components = array('Sendmail','Upload');
  7. function uploadCategory() {
  8. $upldCategory=array();
  9. $upldCategory['photos']="Photo";
  10. $upldCategory['backdrops']="Background";
  11. $upldCategory['corners']="Superimpose";
  12. $upldCategory['texts']="Frames & Borders";
  13. $upldCategory['borders']="Texts & Symbols";
  14. $upldCategory['lines']="Corners & Shapes";
  15. $upldCategory['stickers']="Sports & Calendars";
  16. $upldCategory['sports']="Real & Graphic";
  17. $this->set("uploadCategory",$upldCategory);
  18. }
  19. function pagination($select,$from,$where,$others,$CountField,$arg,$PassParameter) {
  20. if(isset($arg['Page']))
  21. $pageFlag=$arg['Page'];
  22. $this->set("PassParameter",$PassParameter);
  23. $SetUserNumberOfVpsPerPage=SHOW_REC; /* Defined in config->paths.php*/
  24. $this->set("BackgroundClass",'pagination');
  25. $this->set("SelectedPage",'pagination_over');
  26. $this->set("Linkpage",'pagination_over');
  27. $this->set("FirstImage",'fdd.gif');
  28. $this->set("PreviousImage",'previous.gif');
  29. $this->set("NextImage",'next.gif');
  30. $this->set("LastImage",'rewd.gif');
  31. $UserNumberOfVpsPerPage=SHOW_REC; /* Defined in config->paths.php*/
  32. if(!is_numeric($UserNumberOfVpsPerPage)|| (intval($UserNumberOfVpsPerPage)!=$UserNumberOfVpsPerPage)||($UserNumberOfVpsPerPage<=0))
  33. $UserNumberOfVpsPerPage = $SetUserNumberOfVpsPerPage;
  34. if(!isset($arg['Page'])) $arg['Page']=1;
  35. if(!isset($arg['Offset'])) $arg['Offset']=0;
  36. $Query_ForNumber_Records=mysql_query("$select $from $where $others") or die('Line no 120' . mysql_error());
  37. //$Result_Query_ForNumber_Records=mysql_fetch_object($Query_ForNumber_Records);
  38. //$NoOfVps=$Result_Query_ForNumber_Records->NoOfVps;
  39. $NoOfVps=mysql_num_rows($Query_ForNumber_Records);
  40. $NumberOfVpsPerPage=$UserNumberOfVpsPerPage;
  41. $NoOfPages=ceil($NoOfVps/$NumberOfVpsPerPage); //3
  42. if($arg['Offset']==$NoOfVps) {
  43. if(isset($Offset)) {
  44. $Offset=$Offset-$NumberOfVpsPerPage;
  45. $Page--;
  46. if($Offset<0) {
  47. $Offset=0;
  48. $Page=1;
  49. }
  50. }else {
  51. $Offset=0;
  52. $Page=1;
  53. }
  54. }
  55. $this->set("Page",$arg['Page']);
  56. $this->set("Offset",$arg['Offset']);
  57. $this->set("NumberOfVpsPerPage",$NumberOfVpsPerPage);
  58. $this->set("NoOfPages",$NoOfPages);
  59. $this->set("UserNumberOfVpsPerPage",$UserNumberOfVpsPerPage);
  60. //print "$select $from $where $others";
  61. $this->set("qryOthr","$select $from $where");
  62. //echo "$select $from $where $others LIMIT ".$arg['Offset'].",$NumberOfVpsPerPage";
  63. $SelectRecord = mysql_query("$select $from $where $others LIMIT ".$arg['Offset'].",$NumberOfVpsPerPage") or die('Line no '.__LINE__ . mysql_error());
  64. $this->set("query",$SelectRecord);
  65. }
  66. function tagimages() {
  67. $this->checkSession();
  68. $this->layout = 'tagimages';
  69. $this->set("uploadTitle","Tag Images");
  70. $this->creativetype();
  71. $this->uploadCategory();
  72. $upldCat=0;
  73. $upldType=0;
  74. if(isset($this->params['url']['uploadCategory'])) {
  75. $upldCat=$this->params['url']['uploadCategory'];
  76. $upldType=$this->params['url']['uploadType'];
  77. }
  78. if(isset($this->params['form']['uploadCategory'])) {
  79. $upldCat=$this->params['form']['uploadCategory'];
  80. $upldType=$this->params['form']['uploadType'];
  81. }
  82. if(isset($this->params['url']['upldcat'])) {
  83. $upldCat=$this->params['url']['upldcat'];
  84. $upldType=$this->params['url']['upldtype'];
  85. }
  86. $this->set("upldCat",$upldCat);
  87. $this->set("upldType",$upldType);
  88. //Get the images uploaded by ADMIN
  89. //if(isset($upldCat) && $upldCat!='0' && isset($upldType) && $upldType!='0')
  90. // {
  91. $select=" SELECT * ";
  92. $from=" FROM creative_template_images ";
  93. $where="WHERE creative_type_id='".$upldCat."' AND imgtype='".$upldType."' AND uploader='1' and is_delete='0'";
  94. $others=NULL;
  95. $PassParameter="upldcat=".$upldCat."&upldtype=".$upldType;
  96. $CountField="B.id";
  97. $this->set("controller","creativezones");
  98. $this->set("action","tagimages");
  99. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  100. if(isset($this->params['url']['Page'])) {
  101. $this->render("tagimages2","ajax");
  102. }
  103. // }
  104. }
  105. function deletestatik() {
  106. //pr($this->params);
  107. mysql_query("update creative_template_pages set is_delete='1' where id='".$this->params['url']['id']."'");
  108. $this->redirect("/creativezones/statikimages?uploadCategory=".$this->params['url']['uploadCategory']);
  109. }
  110. function deletetagimg() {
  111. //pr($this->params);
  112. mysql_query("update creative_template_images set is_delete='1' where id='".$this->params['url']['id']."'");
  113. $this->redirect("/creativezones/tagimages?uploadCategory=".$this->params['url']['uploadCategory']."&uploadType=".$this->params['url']['uploadType']);
  114. }
  115. function statikimages() {
  116. $this->checkSession();
  117. $this->layout = 'tagimages';
  118. $this->set("uploadTitle","Statik Images");
  119. $this->creativetype();
  120. $this->uploadCategory();
  121. $upldCat=0;
  122. $upldType=0;
  123. if(isset($this->params['url']['uploadCategory'])) {
  124. $upldCat=$this->params['url']['uploadCategory'];
  125. //$upldType=$this->params['form']['uploadType'];
  126. }
  127. if(isset($this->params['form']['uploadCategory'])) {
  128. $upldCat=$this->params['form']['uploadCategory'];
  129. //$upldType=$this->params['form']['uploadType'];
  130. }
  131. if(isset($this->params['url']['upldcat'])) {
  132. $upldCat=$this->params['url']['upldcat'];
  133. //$upldType=$this->params['url']['upldtype'];
  134. }
  135. $this->set("upldCat",$upldCat);
  136. $this->set("upldType",$upldType);
  137. //Get the images uploaded by ADMIN
  138. //if(isset($upldCat) && $upldCat!='0' && isset($upldType) && $upldType!='0')
  139. // {
  140. $select=" SELECT * ";
  141. $from=" FROM creative_template_pages ";
  142. $where="WHERE creative_type_id='".$upldCat."' AND block='0' and is_delete='0' and template_type='1'";
  143. $others=NULL;
  144. $PassParameter=" ";
  145. $CountField="B.id";
  146. $this->set("controller","creativezones");
  147. $this->set("action","tagimages");
  148. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  149. if(isset($this->params['url']['Page'])) {
  150. $this->render("tagimages2","ajax");
  151. }
  152. // }
  153. }
  154. function savetag() {
  155. $this->set("params",$this->params);
  156. if(isset($this->params['url']['id']) && $this->params['url']['id']!="") {
  157. $this->set("imgId",$this->params['url']['id']);
  158. $sql=mysql_query("SELECT imgdescription FROM creative_template_images WHERE id='".$this->params['url']['id']."'");
  159. $fetchDesc=mysql_fetch_assoc($sql);
  160. $this->set("imgDesc",$fetchDesc['imgdescription']);
  161. $this->render("savetag","ajax");
  162. }
  163. if(isset($this->data['creativexones'])) {
  164. $imgId=$this->data['creativexones']['imgId'];
  165. $imageTag=$this->data['creativexones']['imgTag'];
  166. //setting image description
  167. mysql_query("UPDATE creative_template_images SET imgdescription='".$imageTag."' WHERE id='".$imgId."'");
  168. $this->set("imgId",$imgId);
  169. $this->render("tagsaved","ajax");
  170. }
  171. }
  172. function creativeType() {
  173. $q1=mysql_query("SELECT * FROM creative_type WHERE is_delete='0' ORDER BY id ASC");
  174. $i=0;
  175. while($rwCr=mysql_fetch_array($q1)) {
  176. if($i==0)
  177. $defaultCat[$rwCr['id']]=array($rwCr['creative_name'],$rwCr['creative_description'],$rwCr['creative_image']);
  178. $i++;
  179. $creativeType[$rwCr['id']]=array($rwCr['creative_name'],$rwCr['creative_description'],$rwCr['creative_image']);
  180. }
  181. $this->set("defaultType",$defaultCat);
  182. $this->set("creativeType",$creativeType);
  183. }
  184. function creativeupload() {
  185. $this->checkSession();
  186. if(!empty($this->data)) {
  187. if(strtoupper($this->data['Creativezones']['uploadcat'])=='IMAGES')
  188. $this->redirect("/creativezones/uploadimg?t=".base64_encode($this->data['Creativezones']['templatetype']));
  189. if(strtoupper($this->data['Creativezones']['uploadcat'])=='STATIK')
  190. $this->redirect("/creativezones/uploadstatiktemplate?t=".base64_encode($this->data['Creativezones']['templatetype']));
  191. }
  192. }
  193. function uploadimg() {
  194. $this->checkSession();
  195. $this->layout = 'default_after_login';
  196. $this->set("themeId",$this->params['url']['t']);
  197. }
  198. function uploadstatiktemplate() {
  199. $this->checkSession();
  200. $this->layout = 'default_after_login';
  201. $this->set("themeId",$this->params['url']['t']);
  202. }
  203. function uploadimage1() {
  204. $this->checkSession();
  205. $this->layout = 'default_after_login';
  206. $this->set("uploadTitle","Upload Images");
  207. $this->set("upldType","images");
  208. $this->creativeType();
  209. }
  210. function uploadstatik() {
  211. $this->checkSession();
  212. $this->layout = 'default_after_login';
  213. $this->set("uploadTitle","Upload Statik Templates");
  214. $this->set("upldType","statik");
  215. $this->creativeType();
  216. $this->render("uploadimage");
  217. }
  218. function managetax() {
  219. $this->checkSession();
  220. $this->layout = 'default_user';
  221. if(isset($this->data['Sale']['tax'])) {
  222. mysql_query("UPDATE creative_saletax SET tax='".$this->data['Sale']['tax']."' WHERE user_id='1' AND state_id='".$this->data['Sale']['sid']."'") or die(mysql_error());
  223. }
  224. $saletaxarr = array();
  225. $sqlsatetax = "select countries.id , countries.country_name , creative_saletax.user_id from creative_saletax , state , countries where user_id = '1' and state_id=state.id and state.c_id=countries.id Group by countries.id";
  226. $sqlsatetax_res = mysql_query($sqlsatetax);
  227. $sqlsatetax_num = mysql_num_rows($sqlsatetax_res);
  228. if($sqlsatetax_num > 0) {
  229. while($sqlsatetax_res_arr = mysql_fetch_array($sqlsatetax_res)) {
  230. $saletaxarr[$sqlsatetax_res_arr['id']] = $sqlsatetax_res_arr['country_name'] ;
  231. }
  232. }
  233. $this->set('saltaxnum', $sqlsatetax_num);
  234. $this->set('saltaxinfo', $saletaxarr);
  235. }
  236. function savesaletax() {
  237. $this->checkSession();
  238. $this->layout = 'default_user';
  239. $this->pageTitle = 'Sale Tax';
  240. $stateTax = $_REQUEST['saletax'] ;
  241. foreach($stateTax as $stateTax_index=> $stateTax_value ) {
  242. if(isset($_REQUEST['saletax'][$stateTax_index]) && $_REQUEST['saletax'][$stateTax_index]!="") {
  243. $mynumber = $_REQUEST['saletax'][$stateTax_index] ;
  244. if($mynumber>0) {
  245. if (preg_match ("/^([0-9.,-]+)$/", $mynumber)) {
  246. /* Saving in the sale tax */
  247. $selectrec = "select * from creative_saletax where user_id = '1' and state_id = ".$stateTax_index."" ;
  248. $selectrec_res = mysql_query($selectrec);
  249. if(mysql_num_rows($selectrec_res)>0) {
  250. $saletaxsql = "Update creative_saletax SET tax = ".$mynumber." where user_id = '1' and state_id = ".$stateTax_index."" ;
  251. }
  252. else {
  253. $saletaxsql = "INSERT INTO creative_saletax SET tax = ".$mynumber." , user_id = '1' , state_id = ".$stateTax_index."" ;
  254. }
  255. mysql_query($saletaxsql)or die(mysql_error());
  256. /* */
  257. }
  258. }
  259. }
  260. }
  261. $redirectURL = "creativezones/managetax";
  262. $this->redirect($redirectURL);
  263. }
  264. function managecoupon() {
  265. $this->checkSession();
  266. $this->layout = 'default_user';
  267. if(isset($_REQUEST['chkAll']) && $_REQUEST['chkAll']=='checkbox' && isset($_REQUEST['box'])) {
  268. foreach($_REQUEST['box'] as $boxind=>$boxvalue) {
  269. $chkCoupon="DELETE FROM creative_coupon WHERE user_id='1' AND id='".$boxvalue."'";
  270. $chkCoupon_res = mysql_query($chkCoupon);
  271. }
  272. }
  273. }
  274. function addcoupon() {
  275. $this->checkSession();
  276. $this->layout = 'default_user';
  277. }
  278. function savecoupon($couponid=null) {
  279. $this->checkSession();
  280. $this->layout = 'default_user';
  281. //pr($_REQUEST);
  282. $copFrm = $_REQUEST['fromyear'] .'-'.$_REQUEST['frommonth'] .'-'.$_REQUEST['fromdate'] ;
  283. $copTo = $_REQUEST['toyear'] .'-'.$_REQUEST['tomonth'] .'-'.$_REQUEST['todate'] ;
  284. if($couponid) {
  285. $coupQry = "update creative_coupon set coupon_code = '".$this->data['creativezone']['coupon_code']."', coupon_value = ".$this->data['creativezone']['coupon_value'].", coupon_from = '".$copFrm."', coupon_to = '".$copTo."' where id=".$couponid."";
  286. mysql_query($coupQry);
  287. }
  288. else {
  289. $chkCoupon="SELECT * FROM creative_coupon WHERE user_id='1' AND coupon_code='".$this->data['creativezone']['coupon_code']."'";
  290. if(mysql_num_rows(mysql_query($chkCoupon))==0) {
  291. $coupQry = "insert into creative_coupon values('', '1', '".$this->data['creativezone']['coupon_code']."', ".$this->data['creativezone']['coupon_value'].", '".$copFrm."', '".$copTo."', NOW(), '0')";
  292. mysql_query($coupQry);
  293. }
  294. }
  295. $this->redirect('creativezones/managecoupon');
  296. }
  297. function editcreativecoupon($couponid=null) {
  298. $this->checkSession();
  299. $this->layout = 'default_user';
  300. $chkCoupon="SELECT * FROM creative_coupon WHERE user_id='1' AND id='".base64_decode($couponid)."'";
  301. $chkCoupon_res = mysql_query($chkCoupon);
  302. $chkCoupon_arr = mysql_fetch_array($chkCoupon_res);
  303. $this->set('couponarr',$chkCoupon_arr);
  304. }
  305. function delcreativecoupon($couponid=null) {
  306. $this->checkSession();
  307. $this->layout = 'default_user';
  308. $chkCoupon="DELETE FROM creative_coupon WHERE user_id='1' AND id='".base64_decode($couponid)."'";
  309. $chkCoupon_res = mysql_query($chkCoupon);
  310. $this->redirect('creativezones/managecoupon');
  311. }
  312. function blockunblock($couponid=null,$changestatus=null) {
  313. if($changestatus=='Blocked') {
  314. $blockedstatus = '1';
  315. }
  316. else
  317. $blockedstatus = '0';
  318. $chkCoupon="UPDATE creative_coupon SET blocked = '".$blockedstatus."' WHERE user_id='1' AND id='".base64_decode($couponid)."'";
  319. $chkCoupon_res = mysql_query($chkCoupon);
  320. $this->redirect('creativezones/managecoupon');
  321. }
  322. function salesdata() {
  323. $this->checkSession();
  324. $this->layout = 'default_user';
  325. $select = "SELECT PM.*,TC.* ,USR.first_name,USR.last_name,USR.email, COUNTRY.country_name, F.ssn_id,COUNT(CDT.id) as num_item,FX.is_blocked";
  326. $from = " FROM transaction_creatives as TC
  327. LEFT JOIN payment_transactions PM ON ( PM.id = TC.payment_ts_id )
  328. LEFT JOIN creative_carts C ON ( C.transaction_creative_id = TC.id )
  329. LEFT JOIN creative_cart_details CDT ON ( CDT.creative_cart_id = C.id )
  330. LEFT JOIN creative_favorites F ON ( F.id = CDT.creative_favorite_id)
  331. LEFT JOIN creative_favorites FX ON (F.template_id>0 AND F.template_id=FX.id)
  332. LEFT JOIN user_details USR ON ( PM.user_id = USR.user_id )
  333. LEFT JOIN countries COUNTRY ON ( USR.c_id = COUNTRY.id )";
  334. $where = " WHERE TC.pay_status = '1' ";
  335. $others=" GROUP BY TC.id DESC
  336. ORDER BY TC.trandate DESC ";
  337. $searchpass = '';
  338. if(isset($_REQUEST['invoice']) && $_REQUEST['invoice']!='') {
  339. $where.=" AND TC.invoice like '%".$_REQUEST['invoice']."%' ";
  340. $searchpass .= "&invoice=".$_REQUEST['invoice'] ;
  341. $others .=", TC.invoice ";
  342. }
  343. if(isset($_REQUEST['email']) && $_REQUEST['email']!='') {
  344. $where.=" AND USR.email like '%".$_REQUEST['email']."%' ";
  345. $searchpass .= "&email=".$_REQUEST['email'] ;
  346. $others .=", USR.email ";
  347. }
  348. if(isset($_REQUEST['prodid']) && $_REQUEST['prodid']!='') {
  349. $where.=" AND F.ssn_id like '%".$_REQUEST['prodid']."%' ";
  350. $searchpass .= "&prodid=".$_REQUEST['prodid'] ;
  351. $others .=", F.ssn_id ";
  352. }
  353. if(isset($_REQUEST['country']) && $_REQUEST['country']!='') {
  354. $where.=" AND COUNTRY.country_name like '%".$_REQUEST['country']."%' ";
  355. $searchpass .= "&country=".$_REQUEST['country'] ;
  356. $others .=", COUNTRY.country_name ";
  357. }
  358. if(isset($_REQUEST['first_name']) && $_REQUEST['first_name']!='') {
  359. $where.=" AND USR.first_name like '%".$_REQUEST['first_name']."%' ";
  360. $searchpass .= "&first_name=".$_REQUEST['first_name'] ;
  361. $others .=", USR.first_name ";
  362. }
  363. if(isset($_REQUEST['last_name']) && $_REQUEST['last_name']!='') {
  364. $where.=" AND USR.last_name like '%".$_REQUEST['last_name']."%' ";
  365. $searchpass .= "&last_name=".$_REQUEST['last_name'] ;
  366. $others .=", USR.last_name ";
  367. }
  368. if(isset($_REQUEST['datefrom']) && $_REQUEST['datefrom']!='mm/dd/YY' && isset($_REQUEST['dateto']) && $_REQUEST['dateto']!='mm/dd/YY') {
  369. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['datefrom']));
  370. $urlfromdate = $_REQUEST['datefrom'];
  371. $eventToDate=date("Y-m-d",strtotime($_REQUEST['dateto'])).' 23:59:59';
  372. $urltodate = $_REQUEST['dateto'];
  373. $where.=" AND TC.trandate BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  374. $searchpass = "&datefrom=".$urlfromdate."&dateto=".$urltodate ;
  375. }
  376. //get number user
  377. $query = "SELECT COUNT(DISTINCT USR.id) as num_user, SUM(TC.total_amount) as total_sale ".$from.$where;
  378. $this->set('sqlnum',$query);
  379. $result = mysql_query($query);
  380. $row = mysql_fetch_assoc($result);
  381. $this->set('num_user',$row['num_user']);
  382. $this->set('total_sale',$row['total_sale']);
  383. $PassParameter =$searchpass;
  384. $CountField="TC.id";
  385. $this->set("controller","creativezones");
  386. $this->set("action","salesdata");
  387. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  388. if(isset($this->params['url']['Page']) || isset($_REQUEST['search'])) {
  389. $this->render("salesdata2","ajax");
  390. }
  391. }
  392. function creative_invoice_detail() {
  393. $this->layout = "blank";
  394. $this->set("tranId",base64_decode($this->params['url']['inv']));
  395. }
  396. function printscrap() {
  397. $this->layout = "blank";
  398. }
  399. function submission() {
  400. $this->checkSession();
  401. $this->layout = 'default_user';
  402. $select = "SELECT TK.ticket_number,TK.creation,TK.status ,USR.first_name,USR.last_name,USR.email, COUNTRY.country_name, F.ssn_id,F.id";
  403. $from = " FROM creative_favorites as F
  404. RIGHT JOIN creative_tickets TK ON (TK.creative_favorites_id = F.id)
  405. LEFT JOIN user_details USR ON ( F.user_id = USR.user_id )
  406. LEFT JOIN countries COUNTRY ON ( USR.c_id = COUNTRY.id )";
  407. $where = " WHERE F.is_temp = '0' ";
  408. $others=" GROUP BY F.id
  409. ORDER BY TK.creation DESC ";
  410. $searchpass = '';
  411. if(isset($_REQUEST['ticket']) && $_REQUEST['ticket']!='') {
  412. $where.=" AND TK.ticket_number like '%".$_REQUEST['ticket']."%' ";
  413. $searchpass .= "&ticket=".$_REQUEST['ticket'] ;
  414. $others .=", TK.ticket_number ";
  415. }
  416. if(isset($_REQUEST['email']) && $_REQUEST['email']!='') {
  417. $where.=" AND USR.email like '%".$_REQUEST['email']."%' ";
  418. $searchpass .= "&email=".$_REQUEST['email'] ;
  419. $others .=", USR.email ";
  420. }
  421. if(isset($_REQUEST['prodid']) && $_REQUEST['prodid']!='') {
  422. $where.=" AND F.ssn_id like '%".$_REQUEST['prodid']."%' ";
  423. $searchpass .= "&prodid=".$_REQUEST['prodid'] ;
  424. $others .=", F.ssn_id ";
  425. }
  426. if(isset($_REQUEST['country']) && $_REQUEST['country']!='') {
  427. $where.=" AND COUNTRY.country_name like '%".$_REQUEST['country']."%' ";
  428. $searchpass .= "&country=".$_REQUEST['country'] ;
  429. $others .=", COUNTRY.country_name ";
  430. }
  431. if(isset($_REQUEST['first_name']) && $_REQUEST['first_name']!='') {
  432. $where.=" AND USR.first_name like '%".$_REQUEST['first_name']."%' ";
  433. $searchpass .= "&first_name=".$_REQUEST['first_name'] ;
  434. $others .=", USR.first_name ";
  435. }
  436. if(isset($_REQUEST['last_name']) && $_REQUEST['last_name']!='') {
  437. $where.=" AND USR.last_name like '%".$_REQUEST['last_name']."%' ";
  438. $searchpass .= "&last_name=".$_REQUEST['last_name'] ;
  439. $others .=", USR.last_name ";
  440. }
  441. if(isset($_REQUEST['datefrom']) && $_REQUEST['datefrom']!='mm/dd/YY' && isset($_REQUEST['dateto']) && $_REQUEST['dateto']!='mm/dd/YY') {
  442. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['datefrom']));
  443. $urlfromdate = $_REQUEST['datefrom'];
  444. $eventToDate=date("Y-m-d",strtotime($_REQUEST['dateto'])).' 23:59:59';
  445. $urltodate = $_REQUEST['dateto'];
  446. $where.=" AND TK.creation BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  447. $searchpass = "&datefrom=".$urlfromdate."&dateto=".$urltodate ;
  448. }
  449. //get number user
  450. $query = "SELECT COUNT(DISTINCT USR.id) as num_user ".$from.$where;
  451. $this->set('sqlnum',$query);
  452. $result = mysql_query($query);
  453. $row = mysql_fetch_assoc($result);
  454. $this->set('num_user',$row['num_user']);
  455. $PassParameter =$searchpass;
  456. $CountField="F.id";
  457. $this->set("controller","creativezones");
  458. $this->set("action","submission");
  459. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  460. if(isset($this->params['url']['Page']) || isset($_REQUEST['search'])) {
  461. $this->render("submission2","ajax");
  462. }
  463. }
  464. function charges() {
  465. $this->checkSession();
  466. $this->layout = 'default_user';
  467. if(isset($_POST['submit'])) {
  468. if($_POST['creative_price']!='')
  469. $this->savePaymentConfig('creative price',$_POST['creative_price'],'price');
  470. if($_POST['creative_artist_price']!='')
  471. $this->savePaymentConfig('creative artist price',$_POST['creative_artist_price'],'price');
  472. if($_POST['creative_commission']!='')
  473. $this->savePaymentConfig('creative commission',$_POST['creative_commission'],'%');
  474. if($_POST['creative_featured']!='')
  475. $this->savePaymentConfig('creative featured',$_POST['creative_featured'],'price');
  476. if($_POST['creative_featured_days']!='')
  477. $this->savePaymentConfig('creative featured days',$_POST['creative_featured_days'],'days');
  478. if($_POST['creative_quantity_sold']!='')
  479. $this->savePaymentConfig('creative quantity sold',$_POST['creative_quantity_sold'],'times');
  480. //save 168 Washington sale_tax
  481. if($_POST['sale_tax']!='')
  482. $this->save_Saletax(1,168,$_POST['sale_tax']);
  483. if($_POST['creative_commission_minimum']!='')
  484. $this->savePaymentConfig('creative commission minimum',$_POST['creative_commission_minimum'],'days');
  485. if($_POST['password_payout']!='')
  486. $this->savePaymentConfig('password payout',$_POST['password_payout'],'days');
  487. //check uppdate price product
  488. if($_POST['creative_artist_price']!='' || $_POST['creative_quantity_sold']!='') {
  489. $artist_price = $this->getPaymentConfig('creative artist price');
  490. $artist_price = $artist_price['config_value'];
  491. $quantity_sold = $this->getPaymentConfig('creative quantity sold');
  492. $quantity_sold = $quantity_sold['config_value'];
  493. $query = "UPDATE creative_favorites SET price='".$artist_price."' WHERE type='0' AND is_republished='1' AND num_sell<".$quantity_sold;
  494. mysql_query($query);
  495. }
  496. }
  497. $this->getPaymentConfig('creative price',true);
  498. $this->getPaymentConfig('creative artist price',true);
  499. $this->getPaymentConfig('creative commission',true);
  500. $this->getPaymentConfig('creative featured',true);
  501. $this->getPaymentConfig('creative featured days',true);
  502. $this->getPaymentConfig('creative quantity sold',true);
  503. $this->getPaymentConfig('creative commission minimum',true);
  504. $this->getPaymentConfig('password payout',true);
  505. $this->get_Saletax(168,true);
  506. }
  507. function save_Saletax($user_id,$state_id,$tax) {
  508. $query = "SELECT id FROM creative_saletax WHERE state_id='".$state_id."' LIMIT 1";
  509. $result = mysql_query($query);
  510. if(mysql_num_rows($result)>0) {
  511. $query = "UPDATE creative_saletax SET tax='".$tax."' WHERE state_id='".$state_id."' LIMIT 1";
  512. }else {
  513. $query = "INSERT INTO creative_saletax SET user_id='".$user_id."', state_id='".$state_id."', tax='".$tax."' ";
  514. }
  515. $this->set('sale_tax',$tax);
  516. mysql_query($query);
  517. }
  518. function get_Saletax($state_id,$is_set=false) {
  519. $query = "SELECT * FROM creative_saletax WHERE state_id='".$state_id."' LIMIT 1";
  520. $result = mysql_query($query);
  521. $row = mysql_fetch_assoc($result);
  522. if($is_set) {
  523. $this->set('sale_tax',$row['tax']);
  524. }
  525. return $row;
  526. }
  527. function savePaymentConfig($config_name,$config_value,$value_type) {
  528. $query = "SELECT id FROM admin_payment_config WHERE config_name='".$config_name."' LIMIT 1";
  529. $result = mysql_query($query);
  530. if(mysql_num_rows($result)>0) {
  531. $query = "UPDATE admin_payment_config SET config_value='".$config_value."', value_type='".$value_type."' WHERE config_name='".$config_name."' LIMIT 1";
  532. }else {
  533. $query = "INSERT INTO admin_payment_config SET config_name='".$config_name."', config_value='".$config_value."', value_type='".$value_type."'";
  534. }
  535. $this->set(str_replace(' ', '_', $config_name),$config_value);
  536. mysql_query($query);
  537. }
  538. function getPaymentConfig($config_name,$is_set=false) {
  539. $query = "SELECT * FROM admin_payment_config WHERE config_name='".$config_name."' LIMIT 1";
  540. $result = mysql_query($query);
  541. $row = mysql_fetch_assoc($result);
  542. if($is_set) {
  543. $this->set(str_replace(' ', '_', $config_name),$row['config_value']);
  544. }
  545. return $row;
  546. }
  547. function ticket_approve() {
  548. $this->layout = "blank";
  549. $this->set("ticket_number",base64_decode($this->params['url']['tk']));
  550. }
  551. function save_ticket_approval() {
  552. //save data
  553. if(isset($_POST['ticket_number'])) {
  554. $status = $_POST['approve']==1 ? 'Approve' : 'Reject';
  555. //
  556. $query = "SELECT TK.ticket_number,TK.creation,TK.status ,USR.first_name,USR.last_name,USR.email, COUNTRY.country_name, F.ssn_id,F.id,F.user_id,USR.email
  557. FROM creative_tickets TK
  558. RIGHT JOIN creative_favorites F ON (TK.creative_favorites_id=F.id)
  559. LEFT JOIN user_details USR ON ( F.user_id = USR.user_id )
  560. LEFT JOIN countries COUNTRY ON ( USR.c_id = COUNTRY.id )
  561. WHERE TK.ticket_number='".$_POST['ticket_number']."'
  562. LIMIT 1 ";
  563. $result = mysql_query($query);
  564. if(mysql_num_rows($result)>0) {
  565. $row = mysql_fetch_assoc($result);
  566. //update ticket
  567. $sql = "UPDATE creative_tickets SET status ='".$status."', msg_to_user='".$_POST['msg_to_user']."' WHERE ticket_number='".$_POST['ticket_number']."' LIMIT 1 ";
  568. mysql_query($sql);
  569. //update favorites
  570. $sql = "UPDATE creative_favorites SET is_approved ='".$_POST['approve']."' WHERE id='".$row['id']."' LIMIT 1 ";
  571. mysql_query($sql);
  572. $row['status'] = $status;
  573. $this->set('row',$row);
  574. //check send mail
  575. $userDetails=$this->getUserDetails($row['user_id']);
  576. $this->Sendmail->Mail();
  577. $this->Sendmail->From(FROMMAIL);
  578. if(isset($row['email'])) {
  579. $this->Sendmail->To($row['email']);
  580. $subject="XOimages - Submission Ticket ".$row['ticket_number'];
  581. $this->Sendmail->Subject($subject);
  582. $this->set("ticket_number",$row['ticket_number']);
  583. $this->Sendmail->layout='email';
  584. $this->Sendmail->view='mail_ticket_'.($_POST['approve']==1 ? 'approve' : 'reject') ;
  585. $this->Sendmail->startup($this);
  586. $messageBody=$this->Sendmail->bodyText();
  587. $this->Sendmail->Body($messageBody); // set the body
  588. $this->Sendmail->Priority(1) ; // set the priority to Low
  589. $this->Sendmail->Send(); // send the mail
  590. //mail sent to the user mail account in the system
  591. $sender=1;
  592. $receiver=$row['user_id'];
  593. $this->senderMail($sender,$receiver,$subject,$messageBody);
  594. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  595. }
  596. }
  597. }
  598. $this->render('save_ticket_approval');
  599. }
  600. function product_detail() {
  601. $this->layout = "blank";
  602. $this->set("prodid",base64_decode($this->params['url']['prodid']));
  603. }
  604. function categories_image() {
  605. $this->checkSession();
  606. $this->layout = 'default_user';
  607. $this->set('pageHeader','Categories Image');
  608. $types= $this->getTypeImage();
  609. $this->set('types',$types);
  610. $this->getCategory($types[0]['id']);
  611. }
  612. function save_categories_image() {
  613. if(isset($_POST['id_type'])) {
  614. if($_POST['name_category']!='') {
  615. if($_POST['id_cate']!='') {
  616. $query = "UPDATE sp_categories SET id_type='".$_POST['id_type']."', name='".$_POST['name_category']."', sequence='".$_POST['sequence']."'
  617. WHERE id='".$_POST['id_cate']."' ";
  618. }else
  619. $query = "INSERT INTO sp_categories SET id_type='".$_POST['id_type']."', name='".$_POST['name_category']."', sequence='".$_POST['sequence']."' ";
  620. mysql_query($query);
  621. }
  622. $this->getCategory($_POST['id_type'],true);
  623. }
  624. }
  625. function removeCategory($id) {
  626. $query = "SELECT id_type FROM sp_categories WHERE id='".$id."' ";
  627. $result = mysql_query($query);
  628. ;
  629. $row= mysql_fetch_assoc($result);
  630. $query = "DELETE FROM sp_categories WHERE id='".$id."' ";
  631. mysql_query($query);
  632. $this->getCategory($row['id_type'],true);
  633. }
  634. function editCategory($id) {
  635. $query = "SELECT * FROM sp_categories WHERE id='".$id."'";
  636. $result = mysql_query($query);
  637. $row = mysql_fetch_assoc($result);
  638. $this->set('cate',$row);
  639. $this->set('id',$id);
  640. $this->render('categories_image_edit','ajax');
  641. }
  642. function getTypeImage() {
  643. $query = "SELECT * FROM sp_type";
  644. $result = mysql_query($query);
  645. $arr = array();
  646. while($row=mysql_fetch_assoc($result)) {
  647. $arr[] = $row;
  648. }
  649. return $arr;
  650. }
  651. function getCategory($id_type,$is_ajax=false) {
  652. $query = "SELECT * FROM sp_categories WHERE id_type='".$id_type."'";
  653. $result = mysql_query($query);
  654. $arr = array();
  655. while($row=mysql_fetch_assoc($result)) {
  656. $arr[] = $row;
  657. }
  658. $this->set('categories',$arr);
  659. if($is_ajax) {
  660. $this->render('categories_image_change_type','ajax');
  661. }
  662. return $arr;
  663. }
  664. function uploadimage() {
  665. $this->checkSession();
  666. $this->layout = 'default_user';
  667. $this->set('pageHeader','Upload Image');
  668. $types= $this->getTypeImage();
  669. $this->set('types',$types);
  670. $id_type = $types[0]['id'];
  671. if(isset($_POST['id_type'])) {
  672. $id_type = $_POST['id_type'];
  673. if($_POST['name']!='' && $_POST['id_categori']!='') {
  674. $is_upload = false;
  675. if($_FILES['src']['tmp_name']!='') {
  676. $folder = '';
  677. switch ($_POST['id_type']) {
  678. case 1: $folder ='photos';
  679. break;
  680. case 2: $folder ='background';
  681. break;
  682. case 3: $folder ='superimpose';
  683. break;
  684. case 4: $folder ='frame';
  685. break;
  686. case 5: $folder ='text_symbol';
  687. break;
  688. case 6: $folder ='calendars';
  689. break;
  690. case 7: $folder ='graphics';
  691. break;
  692. }
  693. $des = '../../flash/library/'.$folder.'/';
  694. if(!file_exists($des)) {
  695. mkdir($des,0777);
  696. }
  697. if(!file_exists($des.'thumb')) {
  698. mkdir($des.'thumb',0777);
  699. }
  700. $this->Upload->upload($_FILES['src'],$des);
  701. if($this->Upload->errors!=null) {
  702. $this->set('error',join('<br/>',$this->Upload->errors));
  703. $is_upload = false;
  704. }
  705. else {
  706. $is_upload = true;
  707. $filesrc = str_replace('../../flash/', '', $this->Upload->_name);
  708. $file['tmp_name'] = $this->Upload->_name;
  709. $this->Upload->_name = $des.'thumb/'.str_replace($des, '', $this->Upload->_name);
  710. $this->Upload->image($file,'resizemin',array(110,80));
  711. $filethumb = str_replace('../../flash/', '', $this->Upload->_name);
  712. }
  713. }
  714. if($_POST['id_photo']=='' && $is_upload) {
  715. $sql = "INSERT INTO sp_photos SET id_categori='".$_POST['id_categori']."', name='".$_POST['name']."', thumb='".$filethumb."',src='".$filesrc."'";
  716. mysql_query($sql);
  717. }elseif ($_POST['id_photo']!='') {
  718. $sql = "UPDATE sp_photos SET id_categori='".$_POST['id_categori']."', name='".$_POST['name']."' ";
  719. if($is_upload)
  720. $sql .=", thumb='".$filethumb."',src='".$filesrc."'";
  721. $sql .=" WHERE id='".$_POST['id_photo']."' ";
  722. mysql_query($sql);
  723. }
  724. }
  725. }
  726. $cates = $this->getCategory($id_type);
  727. $id_cate = (count($cates)==0) ? 0 : $cates[0]['id'];
  728. if(isset($_POST['id_categori']) && $_POST['id_categori']!='') {
  729. $id_cate = $_POST['id_categori'];
  730. }
  731. $this->set('id_type',$id_type);
  732. $this->set('id_cate',$id_cate);
  733. $this->getImage($id_cate);
  734. }
  735. function editImage($id) {
  736. $query = "SELECT * FROM sp_photos WHERE id='".$id."'";
  737. $result = mysql_query($query);
  738. $row = mysql_fetch_assoc($result);
  739. $this->set('photo',$row);
  740. $this->set('id',$id);
  741. $this->render('uploadimage_edit','ajax');
  742. }
  743. function removeImage($id) {
  744. $query = "SELECT * FROM sp_photos WHERE id='".$id."'";
  745. $result = mysql_query($query);
  746. $row = mysql_fetch_assoc($result);
  747. $id_cate = $row['id_categori'];
  748. $query = "DELETE FROM sp_photos WHERE id='".$id."'";
  749. mysql_query($query);
  750. $this->getImage($id_cate,true);
  751. }
  752. function uploadimage_changetype($id_type) {
  753. $cates = $this->getCategory($id_type);
  754. $id_cate = (count($cates)==0) ? 0 : $cates[0]['id'];
  755. $this->getImage($id_cate,true);
  756. }
  757. function getImage($id_categori=null,$is_ajax=false) {
  758. $select = "SELECT * ";
  759. $from = "FROM sp_photos ";
  760. $where = "WHERE id_categori='".$id_categori."'";
  761. if(isset($_REQUEST['id_categori']) && $_REQUEST['id_categori']!='') {
  762. $id_categori = $_REQUEST['id_categori'];
  763. }
  764. $where = "WHERE id_categori='".$id_categori."'";
  765. $searchpass = "id_categori=".$id_categori ;
  766. $others = " ORDER BY name";
  767. $PassParameter =$searchpass;
  768. $CountField="id";
  769. $this->set("controller","creativezones");
  770. $this->set("action","getImage");
  771. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  772. if(isset($this->params['url']['Page']) || $is_ajax) {
  773. $this->render("uploadimage2","ajax");
  774. }
  775. }
  776. function fonts() {
  777. $this->checkSession();
  778. $this->layout = 'default_user';
  779. $this->set('pageHeader','Fonts');
  780. if(isset($_POST['name'])) {
  781. $is_upload = false;
  782. if($_FILES['src']['tmp_name']!='') {
  783. $folder = '';
  784. $des = '../../flash/FlashDesignFont/';
  785. if(!file_exists($des)) {
  786. mkdir($des,0777);
  787. }
  788. $this->Upload->upload($_FILES['src'],$des,NULL,NULL,array('swf'));
  789. if($this->Upload->errors!=null) {
  790. $this->set('error',join('<br/>',$this->Upload->errors));
  791. $is_upload = false;
  792. }
  793. else {
  794. $is_upload = true;
  795. $filesrc = str_replace($des, '', $this->Upload->_name);
  796. $file['tmp_name'] = $this->Upload->_name;
  797. }
  798. }
  799. if($_POST['id_font']=='' && $is_upload) {
  800. $sql = "INSERT INTO sp_fonts SET name='".$_POST['name']."', class_name='".$_POST['class_name']."', active='".(isset($_POST['active']) ? 1:0)."',src='".$filesrc."'";
  801. mysql_query($sql);
  802. }elseif ($_POST['id_font']!='') {
  803. $sql = "UPDATE sp_fonts SET name='".$_POST['name']."', class_name='".$_POST['class_name']."', active='".(isset($_POST['active']) ? 1:0)."' ";
  804. if($is_upload)
  805. $sql .=", src='".$filesrc."'";
  806. $sql .=" WHERE id='".$_POST['id_font']."' ";
  807. mysql_query($sql);
  808. }
  809. }
  810. }
  811. function fonts_list() {
  812. $query = "SELECT * FROM sp_fonts ";
  813. $result = mysql_query($query);
  814. $arr = array();
  815. while($row=mysql_fetch_assoc($result)) {
  816. $arr[] = $row;
  817. }
  818. $this->set('fonts',$arr);
  819. $this->render('fonts_list','ajax');
  820. }
  821. function fonts_edit($id){
  822. $query = "SELECT * FROM sp_fonts WHERE id='".$id."' LIMIT 1";
  823. $result = mysql_query($query);
  824. $this->set('item',mysql_fetch_array($result));
  825. }
  826. function fonts_remove($id){
  827. $query = "SELECT * FROM sp_fonts WHERE id='".$id."' LIMIT 1";
  828. $result = mysql_query($query);
  829. if(($row=mysql_fetch_array($result))){
  830. $des = '../../flash/FlashDesignFont/';
  831. if(file_exists($des.$row['src'])){
  832. @unlink($des.$row['src']);
  833. }
  834. mysql_query("DELETE FROM sp_fonts WHERE id='".$id."' ");
  835. }
  836. $this->fonts_list();
  837. }
  838. function payment_transactions(){
  839. $this->checkSession();
  840. $this->redirect(PAYMENT_ADMIN_URL);
  841. }
  842. }
  843. ?>