<?php
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.messages.php
//+ Email messages admin helper
//+-----------------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file');//check its within this framework

//____DEFAULT TEMPLATE_____________________________
$inner_template = ADMIN_TEMPLATES.'tpl_messages.htm';

//____Check for any Post_____________________

if(isset($_POST['update'])) {

    //__process the form
    $process = new FormProcessor();
    if(!$process->RequiredFields('all')) {

        $notification = $lang['fill_in_all'];

    }
    else {

        //escape the data (any clean further? admin input safe??)
        foreach($_POST as $key => $value) {
          $$key = mysql_real_escape_string($value);
       }
       
       //unescaped fck data
       $welcome_message =  $_POST['welcome_message'];
       $suspended_message =  $_POST['suspended_message'];
       $closed_message =  $_POST['closed_message'];
       $followed_message =  $_POST['followed_message'];
       $direct_message =  $_POST['direct_message'];
       
        //__upate welcome db
        $dbase->UpdateRecord("UPDATE system_messages
                      SET
					  subject= '$welcome_subject',
					  message= '$welcome_message'
					  WHERE title = 'welcome'");

        //__upate closed db
        $dbase->UpdateRecord("UPDATE system_messages
                      SET
					  subject= '$closed_subject',
					  message= '$closed_message'
					  WHERE title = 'closed'");

        //__upate suspended db
        $dbase->UpdateRecord("UPDATE system_messages
                      SET
					  subject= '$suspended_subject',
					  message= '$suspended_message'
					  WHERE title = 'suspended'");

        //__upate followed db
        $dbase->UpdateRecord("UPDATE system_messages
                      SET
					  subject= '$followed_subject',
					  message= '$followed_message'
					  WHERE title = 'followed'");
					  

        //__upate direct message db
        $dbase->UpdateRecord("UPDATE system_messages
                      SET
					  subject= '$direct_subject',
					  message= '$direct_message'
					  WHERE title = 'direct_message'");
					  					  
     //notification   
     $notification = (mysql_error())? $lang['generic_error'] : $lang['request_completed'];

    }
}




//____Lets get current welsome message_____________________
        //__Get welcome db
        $result = $dbase->SelectRecord("SELECT * FROM system_messages
					                    WHERE title = 'welcome'");
        $welcome_message =  $result['message'];
        $welcome_subject =  $result['subject'];
        

        //__Get closed db
         $result = $dbase->SelectRecord("SELECT * FROM system_messages
 					                     WHERE title = 'suspended'");
        $suspended_message =  $result['message'];
        $suspended_subject =  $result['subject'];

        //__Get suspended db
         $result = $dbase->SelectRecord("SELECT * FROM system_messages
      					                 WHERE title = 'closed'");
        $closed_message =  $result['message'];
        $closed_subject =  $result['subject'];

        //__Get followed db
         $result = $dbase->SelectRecord("SELECT * FROM system_messages
      					                 WHERE title = 'followed'");
        $followed_message =  $result['message'];
        $followed_subject =  $result['subject'];
        
        //__Get direct message db
         $result = $dbase->SelectRecord("SELECT * FROM system_messages
      					                 WHERE title = 'direct_message'");
        $direct_message =  $result['message'];
        $direct_subject =  $result['subject'];
        

//____Lets set the pulldowns & general data_______________________
if(isset($_POST['update'])){
        $closed_message =  stripslashes($_POST['closed_message']);
        $closed_subject =  stripslashes($_POST['closed_subject']);
        $suspended_message =  stripslashes($_POST['suspended_message']);
        $suspended_subject =  stripslashes($_POST['suspended_subject']);
        $welcome_message =  stripslashes($_POST['welcome_message']);
        $welcome_subject =  stripslashes($_POST['welcome_subject']);
        $followed_message =  stripslashes($_POST['followed_message']);
        $followed_subject =  stripslashes($_POST['followed_subject']);
        $direct_message =  stripslashes($_POST['direct_message']);
        $direct_subject =  stripslashes($_POST['direct_subject']);
}


    //_____FCK welcome_____________
    include (FCK_EDITOR);
    $sBasePath = BASEURL.'/thirdparty/fckeditor/';
    $oFCKeditor = new FCKeditor('welcome_message');
    $oFCKeditor->BasePath = $sBasePath;
    $oFCKeditor->CustomConfigurationsPath = "fckconfig.js";
    $oFCKeditor->ToolbarSet = 'BasicPlus';//OR manually set to 'Basic', 'BasicPlus' or 'Advanced'
    $oFCKeditor->SkinPath = $sBasePath + 'editor/skins/silver/';
    $oFCKeditor->Value = $welcome_message;
    $oFCKeditor->Width = '650';
    $oFCKeditor->Height = '175';
    $FCKeditor1 = $oFCKeditor->CreateHtml();
    $fck_welcome_message = $FCKeditor1;
    
    
    //_____FCK suspended_____________
    $oFCKeditor2 = new FCKeditor('suspended_message');
    $oFCKeditor2->BasePath = $sBasePath;
    $oFCKeditor2->CustomConfigurationsPath = "fckconfig.js";
    $oFCKeditor2->ToolbarSet = 'BasicPlus';//OR manually set to 'Basic', 'BasicPlus' or 'Advanced'
    $oFCKeditor2->SkinPath = $sBasePath + 'editor/skins/silver/';
    $oFCKeditor2->Value = $suspended_message;
    $oFCKeditor2->Width = '650';
    $oFCKeditor2->Height = '175';
    $FCKeditor2 = $oFCKeditor2->CreateHtml();
    $fck_suspended_message = $FCKeditor2;


    //_____FCK closed_____________
    $oFCKeditor3 = new FCKeditor('closed_message');
    $oFCKeditor3->BasePath = $sBasePath;
    $oFCKeditor3->CustomConfigurationsPath = "fckconfig.js";
    $oFCKeditor3->ToolbarSet = 'BasicPlus';//OR manually set to 'Basic', 'BasicPlus' or 'Advanced'
    $oFCKeditor3->SkinPath = $sBasePath + 'editor/skins/silver/';
    $oFCKeditor3->Value = $closed_message;
    $oFCKeditor3->Width = '650';
    $oFCKeditor3->Height = '175';
    $oFCKeditor3 = $oFCKeditor3->CreateHtml();
    $fck_closed_message = $oFCKeditor3;
    
    //_____FCK followed_____________
    $oFCKeditor4 = new FCKeditor('followed_message');
    $oFCKeditor4->BasePath = $sBasePath;
    $oFCKeditor4->CustomConfigurationsPath = "fckconfig.js";
    $oFCKeditor4->ToolbarSet = 'BasicPlus';//OR manually set to 'Basic', 'BasicPlus' or 'Advanced'
    $oFCKeditor4->SkinPath = $sBasePath + 'editor/skins/silver/';
    $oFCKeditor4->Value = $followed_message;
    $oFCKeditor4->Width = '650';
    $oFCKeditor4->Height = '175';
    $oFCKeditor4 = $oFCKeditor4->CreateHtml();
    $fck_followed_message = $oFCKeditor4;
    
    //_____FCK direct messages_____________
    $oFCKeditor5 = new FCKeditor('direct_message');
    $oFCKeditor5->BasePath = $sBasePath;
    $oFCKeditor5->CustomConfigurationsPath = "fckconfig.js";
    $oFCKeditor5->ToolbarSet = 'BasicPlus';//OR manually set to 'Basic', 'BasicPlus' or 'Advanced'
    $oFCKeditor5->SkinPath = $sBasePath + 'editor/skins/silver/';
    $oFCKeditor5->Value = $direct_message;
    $oFCKeditor5->Width = '650';
    $oFCKeditor5->Height = '175';
    $oFCKeditor5 = $oFCKeditor5->CreateHtml();
    $fck_direct_message = $oFCKeditor5;
?>