<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Store {

 //Function to create seller  account
    public static function createsellerAccount($objStoreVo)
    {
            $objResult                           = new stdClass();
            $tableName                           = DbHelper::setTablePrefix('artists');
            $stotreId                         = DbHelper::insert($tableName, array(  'artist_name'                  =>  generalMethods::escapeString($objStoreVo->artist_name),
                                                                                     'password'                        =>  generalMethods::escapeString($objStoreVo->password),
                                                                                     'first_name'                      =>  generalMethods::escapeString($objStoreVo->first_name),
                                                                                     'last_name'                      =>  generalMethods::escapeString($objStoreVo->last_name),
                                                                                     'address1'                       =>  generalMethods::escapeString($objStoreVo->address1),
                                                                                     'address2'                       =>  generalMethods::escapeString($objStoreVo->address2),
                                                                                     'city'                       =>  generalMethods::escapeString($objStoreVo->city),
                                                                                     'state'                       =>  generalMethods::escapeString($objStoreVo->state),
                                                                                     'country'                       =>  generalMethods::escapeString($objStoreVo->country),
                                                                                     'zip'                       =>  generalMethods::escapeString($objStoreVo->zip),
                                                                                     'fax'                       =>  generalMethods::escapeString($objStoreVo->fax),
                                                                                     'phone'                       =>  generalMethods::escapeString($objStoreVo->phone),
                                                                                     'email'                       =>  generalMethods::escapeString($objStoreVo->email),
                                                                                     'storename'                       =>  generalMethods::escapeString($objStoreVo->storename),
                                                                                     'date_registered'                       =>  generalMethods::escapeString($objStoreVo->date_registered),
                                                                                     'vapproved'                       =>  generalMethods::escapeString($objStoreVo->vapproved),
                                                                                     'commission'                       =>  generalMethods::escapeString($objStoreVo->commission),
                                                                                     'sellerPlanID'                       =>  generalMethods::escapeString($objStoreVo->sellerPlanID),
                                                                                     'defaultflatrate'                       =>  generalMethods::escapeString($objStoreVo->defaultflatrate),
                                                                                     'additionalflatrate'                       =>  generalMethods::escapeString($objStoreVo->additionalflatrate),
                                                                                     'company'                       =>  generalMethods::escapeString($objStoreVo->company),
                                                                                     'seller_time_zone'                       =>  generalMethods::escapeString($objStoreVo->seller_time_zone),
                                                                                     'paypalemail'                       =>  generalMethods::escapeString($objStoreVo->paypalemail)
                                                                                ));
         if($stotreId) {
            $objResult->status                  =    SUCCESS;
            $objResult->data                    =    $stotreId;
         }else{
             $objResult->status                 =    ERROR;
         }

         return $objResult;
    }


    // Get Seller Approval Status
     public static function getSellerApprovalStatus($sellerId)
    {
                 $objResult                      = new stdClass();
                 $tableName                      = DbHelper::setTablePrefix('artists');
                 $selectCase                     =  "artist_id =".generalMethods::escapeString($sellerId);
               
                 $objResultRow                   = DbHelper::selectSingleValue($tableName,'vapproved',$selectCase);
        
         return $objResultRow;

    }


    //check seller paypal email exists in table
     public static function checksellerPaypalemailExists($txtPaypalEmail , $sellerId='')
    {
                 $objResult                      = new stdClass();
                 $tableName                      = DbHelper::setTablePrefix('artists');
                 $selectCase                     =  "paypalemail ='".generalMethods::escapeString($txtPaypalEmail)."' ";
                 if($sellerId!='')
                     {
                        $selectCase.=" AND artist_id!=".generalMethods::escapeString($sellerId);
                     }
                 $objResultRow                   = DbHelper::selectSingleValue($tableName,'artist_id',$selectCase);
         // If user exists then assign user data to result object
                 if($objResultRow) {

                      $objResult->status         =    SUCCESS;
                      $objResult->data           =   $objResultRow; // Assign user record  to object
                 }
                 else{
                     $objResult->status          =  ERROR;
                  }

         return $objResult;
    }
    

     //Insert Plan detials to table 
     public static function savesellerPlanDetails($objplanVo)
    {
            $objResult                               = new stdClass();
            $tableName                               = DbHelper::setTablePrefix('artists_membershipDetails');
            $stotrePlanId                                = DbHelper::insert($tableName, array('artist_id'                  =>  generalMethods::escapeString($objplanVo->artist_id),
                                                                                     'artist_memStartDate'             =>  generalMethods::escapeString($objplanVo->artist_memStartDate),
                                                                                     'artist_memEndDate'              =>  generalMethods::escapeString($objplanVo->artist_memEndDate),
                                                                                     'plan_Id'                       =>  generalMethods::escapeString($objplanVo->plan_Id),
                                                                                     'plan_SubscriptionCharge'       =>  generalMethods::escapeString($objplanVo->plan_SubscriptionCharge)
                                                                                ));
         if($stotrePlanId) {
            $objResult->status                  =    SUCCESS;
            $objResult->data                    =    $stotrePlanId;
         }else{
             $objResult->status                 =    ERROR;
         }

         return $objResult;
    }


         // send Seller previlge mail to seller 
     public static function sendSellerAccountActivationMail($sellerVo)
    {
                $objResult                      =   new stdClass();
                $sellerapproval                 =   getSettingsValue('approve_sellers');

                 $sellerid=$sellerVo->seller_id;
                 
                if($enable_seller_friendly == "Y") {
                     $friendly_url = SITE_URL."/store/".$sellerVo->storename;
                }else{
                    $friendly_url = SITE_URL."/showportfolio.php?artistid=".$sellerid;
                }

                $approvalContent = '';
                
                $sellerapprove_id   = base64_encode($sellerid);

               if($sellerapproval==3 ) { // check if seller approval is through Email - Activation
                   
                    $approvalContent.="<font color='green'><b>".MSG_CLICK_LINK."</b></font><br><br>";
                    $approvalContent.="<a href=".SITE_URL."/sellers_activation.php?aid=$sellerapprove_id&status='Y'>".MSG_CLICK_HERE."</a>";
                    $info_msg        =  MSG_SELLER_ACCOUNT_EMAIL_ACTIVATION;
                } // end email activation check)
                if($sellerapproval==1) {
                    $approvalContent .= MAIL_PLAN_PURCHASE_TEXT_CLICK."&nbsp;<a href=".SITE_URL."/sellers>".MAIL_PLAN_PURCHASE_TEXT_HERE."</a> ".MAIL_PLAN_PURCHASE_TEXT_TO_LOGIN;
                    $info_msg         = MSG_SELLER_ACCOUNT_ACTIVATED;
                }
                if($sellerapproval==2) {
                    $approvalContent .= "<font color='green'><b>".MSG_ACC_APPRV_ADMIN.".</b></font>";
                    $info_msg         = MSG_SELLER_ACCOUNT_ACTIVATION;
                }

               // echo $info_msg;
                
                $mailcontent='<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#F5F5F5;font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; ">
		<tr>
		<td style="font-weight:bold; color:#CE0221; font-size:14px; padding:15px 15px 5px 15px;" align="left" valign="top">
		'.MAIL_SELLER_ACCOUNT_INFO.'
		</td>
		</tr>
		<tr>
		<td  align="left" valign="top" style="padding:5px 15px 15px 15px; ">
		<table width="100%" cellpadding="5" cellspacing="0" border="0" style="background-color:#FFFFFF; border:#D5D5D5 solid 1px;font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; ">
		<tr>
		<td width="40%">'.MAIL_SELLER_STORE_NAME.'</td>
		<td width="60%" style="font-size:13px; color:#991818; font-weight:bold; ">'.$sellerVo->storename.'&nbsp;&nbsp;( <a href='.$friendly_url.' target=_blank> '.MY_FAVOURITES_SELLER_VIEW_STORE.' </a> )</td>
		</tr><tr>
		<td width="40%" colspan="2">'.NOTE_USE_SAME_ACCOUNT_LOGIN.'</td>
		</tr>';
        $mailcontent .= '
		<tr>
		<tr>
		<td colspan=2 >'.$approvalContent.' </td>
		
		</tr>
                <tr>
		<td colspan=2 >&nbsp;</td>

		</tr> 
		<tr>
		</table>
		</td>
		</tr></table>';


        //echo  $mailcontent;

        $mailcontent_seller_approval = readEmailTemplate('seller_previlge_update');
        $mailcontent_seller_approval = str_replace('[account_details]',$mailcontent,$mailcontent_seller_approval);

        $mail_send_details_seller='<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title >'.SITE_NAME.'</title>
  <link href="'.SITE_URL.'/style/template1-admin.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA" >
   <tr>
     <td align="center" valign="top">

         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td bgcolor="#EAEAEA" ><img src='.SITE_URL.'/banners/'.getSettingsValue('site_logo').' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
			<tr>
			<td align="left" height="50"> '.MAIL_ORDER_TEXT_DEAR.' '.$sellerVo->first_name.'&nbsp;'.$sellerVo->last_name.', </td>
			<tr>
			<tr>
			<td align="left">'.$info_msg.'</td>
			</tr>

			<tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left">'.$mailcontent_seller_approval.'</td>
                </tr>

              </table></td>
            </tr>

            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>
</body>
</html>';

        //echo $mail_send_details_seller;
        
        $headers  = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Reply-To: ".SITE_NAME."<".SITE_EMAIL.">" . "\r\n";
        $headers .= "Return-Path: ".SITE_NAME."<noreply@".SITE_NAME.">" . "\r\n";
        $headers .= "Organization: ".SITE_NAME."\r\n";
        $sellermail_flag = MAIL_SELLER_ACTIVATION_SUBJECT." --".SITE_NAME;
        //$sellerVo->email = 'armiatester@gmail.com';
        $mailsent = mail($sellerVo->email,$sellermail_flag,$mail_send_details_seller,$headers);
    }


      // Get Seller account details
      public static function get_seller_account_info($sellerid)
    {
            $objResult                           = new stdClass();
           if(!empty($sellerid)) {
                 $tableName                      = DbHelper::setTablePrefix('artists');
                 $selectCase                     =  "artist_id = ".generalMethods::escapeString($sellerid). " ";
                 $objResultRow                   =  DbHelper::selectRecord($tableName,'*',$selectCase);
         // If user exists then assign user data to result object
                 if($objResultRow) {
                      $objResult->status         =    SUCCESS;
                      $objResult->data           =   $objResultRow; // Assign user record  to object
                 }
                 else{
                     $objResult->status          =  ERROR;
                  }
           }


         return $objResult;
    }


     // Get Seller account details
      public static function get_buyer_account_info($sellerid)
    {
            $objResult                           = new stdClass();
           if(!empty($sellerid)) {
                 $tableName                      = DbHelper::setTablePrefix('users');
                 $selectCase                     =  "seller_id = ".generalMethods::escapeString($sellerid). " ";
                 $objResultRow                   =  DbHelper::selectSingleValue($tableName,'user_id',$selectCase);
         // If user exists then assign user data to result object
                 if($objResultRow) {
                      $objResult->status         =    SUCCESS;
                      $objResult->data           =   $objResultRow; // Assign user record  to object
                 }
                 else{
                     $objResult->status          =  ERROR;
                  }
           }


         return $objResult;
    }
  
    
    // Update seller profile information if single account activated for buyer and seller 

      public static function updateSellerProfileInformation($userObjVo)
    {
            $objResult                           = new stdClass();
            $tableName                           = DbHelper::setTablePrefix('artists');
            $where                               = "artist_id = ".generalMethods::escapeString($userObjVo->seller_id). " ";
            $sellerId                              = DbHelper::update($tableName,array('first_name' => generalMethods::escapeString($userObjVo->first_name),
                                                            'last_name' => generalMethods::escapeString($userObjVo->last_name),
                                                            'address1' => generalMethods::escapeString($userObjVo->address1),
                                                            'address2' => generalMethods::escapeString($userObjVo->address2),
                                                            'city' => generalMethods::escapeString($userObjVo->city),
                                                            'state' => generalMethods::escapeString($userObjVo->state),
                                                            'country' => generalMethods::escapeString($userObjVo->country),
                                                            'zip' => generalMethods::escapeString($userObjVo->zip),
                                                            'email' => generalMethods::escapeString($userObjVo->email),
                                                            'phone' => generalMethods::escapeString($userObjVo->phone),'fax' => generalMethods::escapeString($userObjVo->fax)),$where);
         if($sellerId) {
            $objResult->status                  =    SUCCESS;
            $objResult->data                    =    $sellerId;
         }else{
             $objResult->status                 =    ERROR;
         }

         return $objResult;
    }
    
    
    
    // Update seller password 
    
    
      public static function updateSellerPassword($userObjVo)
    {
            $objResult                           = new stdClass();
            $tableName                           = DbHelper::setTablePrefix('artists');
            $where                               = "artist_id = ".generalMethods::escapeString($userObjVo->seller_id). " ";
            $sellerId                              = DbHelper::update($tableName,array('password' => generalMethods::escapeString($userObjVo->password)),$where);
         if($sellerId) {
            $objResult->status                  =    SUCCESS;
            $objResult->data                    =    $sellerId;
         }else{
             $objResult->status                 =    ERROR;
         }

         return $objResult;
    }
    
    
    //Check flat rate settings already available
    
      public static function get_seller_flat_rate_exists($objVo)
    {
            $objResult                           = new stdClass();
           if(!empty($objVo)) {
                 $tableName                      = DbHelper::setTablePrefix('flat_rate_seller');
                 $selectCase                     =  "flat_rate_name = '".generalMethods::escapeString($objVo->flat_rate_name)."' AND seller_id = ".generalMethods::escapeString($objVo->seller_id). " ";
                 $objResultRow                   =  DbHelper::selectSingleValue($tableName,'flat_rate_seller_id',$selectCase);
         // If user exists then assign user data to result object
                return $objResultRow;
           }
           

       }
    
}
?>
