<?php
/**
 * appRain CMF
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */

// Data edit or update
if( $action == 'update' ||  $action == 'add' ){
    $data_list = isset($this->data['Member'])?$this->data['Member']:$data_list;
    $data_list['id'] = isset( $data_list['id'] ) ? $data_list['id'] : "";
    $data_list['name_title'] = isset( $data_list['name_title'] ) ? $data_list['name_title'] : "";
    $data_list['f_name'] = isset( $data_list['f_name'] ) ? $data_list['f_name'] : "";
    $data_list['l_name'] = isset( $data_list['l_name'] ) ? $data_list['l_name'] : "";
    $data_list['login_name'] = isset( $data_list['login_name'] ) ? $data_list['login_name'] : "";
    $data_list['login_password'] = isset( $data_list['login_password'] ) ? $data_list['login_password'] : "";
    $data_list['email'] = isset( $data_list['email'] ) ? $data_list['email'] : "";
    $data_list['phone_no'] = isset( $data_list['phone_no'] ) ? $data_list['phone_no'] : "";
    $data_list['address'] = isset( $data_list['address'] ) ? $data_list['address'] : "";
    $data_list['state'] = isset( $data_list['state'] ) ? $data_list['state'] : "";
    $data_list['zipcode'] = isset( $data_list['zipcode'] ) ? $data_list['zipcode'] : "";
    $data_list['phone_no'] = isset( $data_list['zipcode'] ) ? $data_list['zipcode'] : "";
    $data_list['country'] = isset( $data_list['country'] ) ? $data_list['country'] : "";
    $data_list['website'] = isset( $data_list['website'] ) ? $data_list['website'] : "";
    $data_list['pay_date'] = isset( $data_list['pay_date'] ) ? $data_list['pay_date'] : "";
    $data_list['status'] = isset( $data_list['status'] ) ? $data_list['status'] : "";
	$data_list['note'] = isset( $data_list['note'] ) ? $data_list['note'] : "";
	
?>
	<form method="post" action="<?php echo $this->baseurl("/member/manage/$action/" . $data_list['id']); ?>">

    <div class="box box-left box-padding box-left-tabs">
        <div class="title">
            <h5><?php echo $this->__('Personal Information');?></h5>
        </div>        
        <div id="box-left-forms">
            <div class="form">
                <div class="fields">
					<div class="field">
                        <div class="label">
                            <label for="name_title"><?php echo $this->__("Name Title:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->selectTag("data[Member][name_title]",array("Mr." =>"Mr.","Mrs." =>"Mrs.","Dr." =>"Dr." ),$data_list['name_title'],array('id' => 'name_title',"class"=>" check_notempty"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="f_name"><?php echo $this->__("First Name:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][f_name]",$data_list['f_name'],array("id"=>"f_name","class"=>"app_input check_notempty"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="l_name"><?php echo $this->__("Last Name:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][l_name]",$data_list['l_name'],array("id"=>"l_name","class"=>"app_input check_notempty"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="phone_no"><?php echo $this->__("Phone No:"); ?></label>
                        </div>
                        <div class="l_name">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][phone_no]",$data_list['phone_no'],array("id"=>"phone_no","class"=>"app_input"));?>
                        </div>
                    </div>			
                    <div class="field">
                        <div class="label">
                            <label for="state"><?php echo $this->__("State:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][state]",$data_list['state'],array("id"=>"state","class"=>"app_input "));?>
                        </div>
                    </div>					
                    <div class="field">
                        <div class="label">
                            <label for="zipcode"><?php echo $this->__("Zipcode:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][zipcode]",$data_list['zipcode'],array("id"=>"zipcode","class"=>"app_input "));?>
                        </div>
                    </div>					
                    <div class="field">
                        <div class="label">
                            <label for="country"><?php echo $this->__("Country:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->countryTag("data[Member][country]",$data_list['country'],array('id' => 'country','class'=>"check_notempty"));?>
                        </div>
                    </div>	
                    <div class="field">
                        <div class="label">
                            <label for="website"><?php echo $this->__("Website:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][website]",$data_list['website'],array("id"=>"website","class"=>"app_input"));?>
                        </div>
                    </div>	
					<div class="field">
                        <div class="label">
                            <label for="status"><?php echo $this->__("Status:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->selectTag("data[Member][status]",array("Applied"=>"Applied","Active"=>"Active","Pending"=>"Pending"),$data_list['status'],array("id"=>"status"));?>
                        </div>
                    </div>						
                </div>
            </div>
        </div>       
    </div>

    <div class="box box-right">
        <div class="title">
            <h5><?php echo $this->__("Other Information");?></h5>
        </div>
        <div id="box-left-other">
            <div class="form">
                <div class="fields">
					<div class="field">
                        <div class="label">
                            <label for="email"><?php echo $this->__("Email Address:"); ?></label>
                        </div>
                        <div class="input">
						<?php if($action == 'add'):?>
                            <?php echo App::load("Helper/Html")->inputTag("data[Member][email]",$data_list['email'],array("id"=>"email","class"=>"app_input check_email"));?>
						<?php else:?>
							<?php echo App::load("Helper/Html")->inputTag("data[Member][email]",$data_list['email'],array("disabled"=>"disabled","id"=>"email","class"=>"app_input check_email","style"=>"background-color:#EEE"));?>
						<?php endif;?>
                        </div>
                    </div>				
                    <div class="field">
                        <div class="label">
                            <label for="password"><?php echo $this->__("Password:"); ?></label>
                        </div>
                        <div class="input">
							<?php if($action == 'add'):?>
								<?php echo App::load("Helper/Html")->passwordTag("data[Member][password]",'',array("id"=>"password","class"=>"app_input check_notempty"));?>
							<?php else:?>
								<?php echo App::load("Helper/Html")->passwordTag("data[Member][password]",'',array("disabled"=>"disabled","id"=>"password","class"=>"app_input check_notempty","style"=>"width:300px;background-color:#EEE"));?> <input type="checkbox" id="password_chk"  onclick="enabledisable(this,'#password')" /> <label class="label-checkbox"  for="password_chk">Enable</label>	
							<?php endif;?>	
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="cpassword"><?php echo $this->__("Confirm New Password:"); ?></label>
                        </div>
                        <div class="input">
							<?php if($action == 'add'):?>
								<?php echo App::load("Helper/Html")->passwordTag("data[Member][cpassword]",'',array("id"=>"cpassword","class"=>"app_input check_notempty"));?>
							<?php else:?>
								<?php echo App::load("Helper/Html")->passwordTag("data[Member][cpassword]",'',array("disabled"=>"disabled","id"=>"cpassword","class"=>"app_input check_notempty","style"=>"width:300px;background-color:#EEE"));?> <input type="checkbox" id="cpassword_chk" onclick="enabledisable(this,'#cpassword')" /> <label class="label-checkbox" for="cpassword_chk">Enable</label>
							<?php endif;?>								
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="address"><?php echo $this->__("Address:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->textareaTag("data[Member][address]",$data_list['address'],array("id"=>"address","rows"=>"7","class"=>"app_input check_notempty"));?>
                        </div>
                    </div>						
                    <div class="field">
                        <div class="label">
                            <label for="note"><?php echo $this->__("Note:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->textareaTag("data[Member][note]",$data_list['note'],array("rows"=>"14","id"=>"note","class"=>"app_input"));?>
                        </div>
                    </div>
                    <div class="buttons">
						<input type="submit" title="Save Entry" value="Save" name="Button[button_save]" /> 
						<input type="submit" title="Save and Continue" value="Save and Continue" name="Button[button_save_and_update]" /> 
						<input type="button" value="&lt;&lt; Back" onclick="javascript:history.go(-1)" name="Button[Back]" />
                    </div>
                </div>
            </div>
        </div>
        <?php  App::Helper('JavaScript')->appForm('form');?>

    </div>
</form>
<script type="text/javascript">
	function enabledisable(e,te){
		if(jQuery(e).attr('checked')){
			jQuery(te).css('background-color','#FFF');
		}
		else{
			jQuery(te).css('background-color','#EEE');
		}
		jQuery(te).attr('disabled',!jQuery(e).attr('checked'));
	}
</script>
<?php
}
else if ( $action =='view'){
    App::Helper('Toolbar')->setTitle("{$data_list['f_name']} {$data_list['l_name']}")->setBtnBack()->Render(array('code'=>'member_view_top'));
    App::Module('DataGrid')
		->setDisplay('FormListing')
	   ->addRow("Name Title",$data_list['name_title'])
	   ->addRow("First Name",$data_list['f_name'])
	   ->addRow("Last Name",$data_list['l_name'])
	   ->addRow("Email",$data_list['email'])
	   ->addRow("Phone No",$data_list['phone_no'])
	   ->addRow("Address",App::Load("Helper/Utility")->codeFormated($data_list['address']))
	   ->addRow("State",$data_list['state'])
	   ->addRow("Zipcode",$data_list['zipcode'])
	   ->addRow("Country",App::Load("Helper/Utility")->countryCodeToName($data_list['country']))
	   ->addRow("Website",$data_list['website'])
	   ->addRow("Date Signup",App::Load("Helper/Date")->dateFormated($data_list['signup_date']))
	   ->addRow("Status",$data_list['status'])
	   ->Render();
    App::Helper('Toolbar')->setBtnBack()->setFormJustified(true)->Render(array('code'=>'member_view_bottom'));
}
else{
	 echo $this->get_tag('form',array('action'=>$this->baseurl("/member/manage/"),'method'=>'post'));
    App::Helper('Toolbar')->setTitle("View Members")->setBtnCustomHTML(App::Helper("Html")->submitTag("data[Button][Delete]","Delete"))->setBtnBack()->Render(array('code'=>'member_list_view_top'));
    if(!empty($data_list['data']))
    {
        $Grid = App::Module('DataGrid');
        $Grid->setHeader(array($this->get_tag('input',array('type'=>'checkbox','class'=>'checkall')),'#','First Name', 'Last Name', 'Email','Status','Options'));
        $Grid->setFooter($data_list['paging_str']);
        foreach($data_list['data'] as $key=>$val)
        {
            $Grid->addRow(
				$this->get_tag('input',array('name'=>'data[id][]','type'=>'checkbox','value'=>"{$val['id']}","class"=>"checkrow")),
				(($data_list["page"] - 1) * $this->get_config('default_pagination') + $key + 1),
				$val['f_name'],
				$val['l_name'],
				$val['email'],
				$val['status'],
				  App::load("Helper/Html")->linkTag($this->baseurl('/member/manage/view/' . $val['id'] ),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/view.gif'),array('title' => 'View ',NULL,'alt'=>'View',"class"=>"icon")),array("title"=>"View user information"))
				. App::load("Helper/Html")->linkTag($this->baseurl('/member/manage/update/' . $val['id']),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/edit.gif'),NULL,array('title'=>'Edit ','alt' => 'Edit',"class"=>"icon")),array("title"=>"Edit user information"))
				. App::load("Helper/Html")->linkTag("javascript:void(0)",App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif'),NULL,array('title'=>'Delete','alt'=>'Delete')),array('id'=>'Member','class'=>'link_delete icon', 'title'=>'Member_' . $val['id']))
			);
        }
        $Grid->Render();
		echo $this->get_tag("/form");
    }
    else
    {
        echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
    }

    App::Helper('Toolbar')->setBtnCustomHTML(App::Helper("Html")->submitTag("data[Button][Delete]","Delete"))->setBtnBack()->Render(array('code'=>'member_list_view_bottom'));
}
