Location: PHPKode > projects > MembersGear > membersgear/admin/admin_product_canned_email_m.php
<?php
  require_once "../config/config.php";
  
  require_once "../includes/cannedemail_class.php";
  
  $loCannedEmail = new cannedemail_class();

  switch($_action)
  {
        case 'insert':
                    $lTypes=null;
                    
                    /****************Delete template if it is already exist***********************/
                    
                    $templateDelQuery = 'DELETE FROM '.TABLE_PREFIX.'email_templates WHERE productid=? AND name=?';
                    $liProductID = array($_POST['hdnProductID'],$_POST['txtName']);
                    $liDelTemplate = $loCannedEmail->Delete($templateDelQuery,$liProductID,null);
                    
                    /****************************************************************************/
                    
                    $query = 'INSERT INTO '.TABLE_PREFIX.'email_templates
                            (name, productid, sendmessageto, status, sender_name, sender_email, email_format, email_subject, email_copy_to, email_message, email_attachment, admin_email_format, admin_email_subject, admin_email_message, createdby, createdon, createdipaddress)
                            VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
                            //VALUES('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1)'
                            
                    $lsValues = array();         

                    $lsValues[0] = $_POST['txtName'];
                    $lsValues[1] = $_POST['hdnProductID'];
                    if($_POST['ddlSendMessageTo'] == '1')
                    {
                        $lsValues[2] = 'User';    
                    }
                    elseif($_POST['ddlSendMessageTo'] == '2')
                    {
                        $lsValues[2] = 'Admin';    
                    }
                    elseif($_POST['ddlSendMessageTo'] == '3')
                    {
                        $lsValues[2] = 'Both';    
                    }                        
                    
                    $lsValues[3] = $_POST['ddlStatus'];
                    $lsValues[4] = $_POST['txtSenderName'];
                    $lsValues[5] = $_POST['txtSenderEmail'];
                    $lsValues[6] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['ddlUserEmailFormat'] : ' ';
                    $lsValues[7] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailSubject'] : ' ';
                    $lsValues[8] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailCopyTo'] : ' ';
                    $lsValues[9] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailMessage'] : ' ';
                    $lsValues[10] = $_POST['dirlist'];
                    $lsValues[11] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['ddlAdminEmailFormat'] : ' ';
                    $lsValues[12] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['txtAdminEmailSubject'] : ' ';
                    $lsValues[13] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['txtAdminEmailMessage'] : ' ';
                    $lsValues[14] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                    $lsValues[15] = mktime();
                    $lsValues[16] = $_SERVER['REMOTE_ADDR'];


                    $lsInsertedrows = $loCannedEmail->Insert($query,$lsValues,$lTypes);
                    /*
                    if($lsInsertedrows)
                    {
                        $message->SetMessage('Canned Email created successfully.');
                    }
                    else
                    {
                        $message->SetMessage('Some error occure while insert record.');
                    }     
                    Redirect('admin_product_canned_email_v.php');
                    */
                    if($lsInsertedrows)
                    {
                        $query="SELECT * FROM ".TABLE_PREFIX ."email_templates WHERE id=(SELECT MAX(id) FROM  ".TABLE_PREFIX ."email_templates)";
                        
                        $lsResultData = $loCannedEmail->View($query);
                        
                        echo "<script language=\"JavaScript\">";
                        echo "top.window.opener.SetEmailTemplateID('".$_POST['hdnEmailFor']."',".$lsResultData[0]['id'].",'".$lsResultData[0]['name']."');";
                        echo "top.window.close();";
                        echo "</script>";
                    }
            
                break;
        case 'update':
                    $lTypes=null;   
                    $query = 'UPDATE '.TABLE_PREFIX.'email_templates SET name=?, productid=?, sendmessageto=?, status=?, sender_name=?, sender_email=?, email_format=?, email_subject=?, email_copy_to=?, email_message=?, email_attachment=?, admin_email_format=?, admin_email_subject=?, admin_email_message=?, modifiedon=?, modifiedby=?, modifiedipaddress=?  WHERE id=? and productid=?';
                            
                                                        
                    $lsValues = array();         

                    $lsValues[0] = $_POST['txtName'];
                    $lsValues[1] = $_POST['hdnProductID'];
                    
                    if($_POST['ddlSendMessageTo'] == '1')
                    {
                        $lsValues[2] = 'User';    
                    }
                    elseif($_POST['ddlSendMessageTo'] == '2')
                    {
                        $lsValues[2] = 'Admin';    
                    }
                    elseif($_POST['ddlSendMessageTo'] == '3')
                    {
                        $lsValues[2] = 'Both';    
                    }
                    
                    $lsValues[3] = $_POST['ddlStatus'];
                    $lsValues[4] = $_POST['txtSenderName'];
                    $lsValues[5] = $_POST['txtSenderEmail'];
                    $lsValues[6] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['ddlUserEmailFormat'] : ' ';
                    $lsValues[7] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailSubject'] : ' ';
                    $lsValues[8] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailCopyTo'] : ' ';
                    $lsValues[9] = ($lsValues[2] == 'User' || $lsValues[2] == 'Both') ? $_POST['txtUserEmailMessage'] : ' ';
                    $lsValues[10] = $_POST['dirlist'];
                    $lsValues[11] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['ddlAdminEmailFormat'] : ' ';
                    $lsValues[12] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['txtAdminEmailSubject'] : ' ';
                    $lsValues[13] = ($lsValues[2] == 'Admin' || $lsValues[2] == 'Both') ? $_POST['txtAdminEmailMessage'] : ' ';
                    $lsValues[14] = mktime();
                    $lsValues[15] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
                    $lsValues[16] = $_SERVER['REMOTE_ADDR'];
                    $lsValues[17] = $_POST['hdnID'];
                    $lsValues[18] = $_POST['hdnProductID'];

                    $lsUpdatedrows = $loCannedEmail->Update($query,$lsValues,$lTypes);

                    if($lsUpdatedrows > 0)
                    {
                        //$message->SetMessage('Canned email updated successfully.');
                        echo "<script language=\"JavaScript\">";
                        echo "top.window.opener.SetEmailTemplateID('".$_POST['hdnEmailFor']."',".$_POST['hdnID'].",'".$_POST['txtName']."');";
                        echo "top.window.close();";
                        echo "</script>";
                    }
                         
                    //Redirect('admin_product_canned_email_v.php');

                    
                break;
        case 'edit':
                     $lTypes=null;
                     $lsValues = array($_GET['id']);
                     $query = "SELECT * FROM ".TABLE_PREFIX."email_templates WHERE id=?";
                     
                     $result = $loCannedEmail->View($query,$lsValues,null);
                     
                     $_SESSION['path'] = $result[0]['email_attachment'];
                     
                     $smarty->assign('data',$result);
                     $smarty->assign('ProductID',$_GET['pid']);
                     $smarty->assign('EmailFor',$_GET['emailfor']);
                     
                     $smarty->assign('IsEdit','yes');
                     $smarty->display('admin_product_canned_email_m.tpl');
                break;        
       /* 
        case 'delete':
                      $lTypes=null;
                      if(empty($_GET['id']) and $_GET['id'] == '')
                      {
                            $message->SetMessage('Invalid id suplied. Please try again.');
                            Redirect('admin_canned_email_v.php');   
                      }
                      $lsValues = array($_GET['id']);
                      $query = "DELETE FROM ".TABLE_PREFIX."email_templates WHERE id=?";
                      
                      $lsDeletedrow = $loCannedEmail->Delete($query,$lsValues,null);
        
                      if($lsDeletedrow > 0)
                      {
                            $message->SetMessage('Some error occure while deleting record.');
                      }
                      else
                      {
                            $message->SetMessage('Record delete successfully.');
                      }  
                      Redirect('admin_product_canned_email_v.php'); 
                break;
        */
        default:
                $smarty->assign('EmailFor',$_GET['emailfor']);
                
                if($_GET['emailfor'] == 'chkCustomized_Signup')
                {
                      $smarty->assign('CannedEmailName','Product signup completed');
                }
                elseif($_GET['emailfor'] == 'chkexpnotification')
                {
                       $smarty->assign('CannedEmailName','Subscription expired');
                }
                $smarty->assign('ProductID',$_GET['pid']);
               
                $smarty->display('admin_product_canned_email_m.tpl');                                  
  }
?>
Return current item: MembersGear