
<?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
 */
 ?>

<?php if( $action == 'update' ||  $action == 'add' ): ?>

<?php
$adminlist = isset($this->data["Admin"]) ? $this->data["Admin"] : $adminlist;
$adminlist['id'] = isset( $adminlist['id'] ) ? $adminlist['id'] : "";
$adminlist['f_name'] = isset( $adminlist['f_name'] ) ? $adminlist['f_name'] : "";
$adminlist['l_name'] = isset( $adminlist['l_name'] ) ? $adminlist['l_name'] : "";
$adminlist['username'] = isset( $adminlist['username'] ) ? $adminlist['username'] : "";
$adminlist['password'] = isset( $adminlist['password'] ) ? $adminlist['password'] : "";
$adminlist['cpassword'] = isset( $adminlist['cpassword'] ) ? $adminlist['cpassword'] : $adminlist['password'];
$adminlist['email'] = isset( $adminlist['email'] ) ? $adminlist['email'] : "";
$adminlist['acl'] = isset( $adminlist['acl'] ) ? $adminlist['acl'] : "";
$adminlist['description'] = isset( $adminlist['description'] ) ? $adminlist['description'] : "";
$adminlist['status'] = isset( $adminlist['status'] ) ? $adminlist['status'] : "";
$adminlist['type'] = isset( $adminlist['type'] ) ? $adminlist['type'] : "Normal";
?>

<form method="post" action="<?php echo $this->baseUrl("/admin/manage/$action/" . $adminlist['id']); ?>">

    <div class="box box-left box-padding box-left-tabs">
        <div class="title">
            <h5><?php echo $this->__('Personal Information');?></h5>
            <ul class="links">
                <?php if($action == 'add'):?>
                     <li><a href="#box-left-forms"><?php echo $this->__("User Data");?></a></li>
                <?php else:?>
                     <li><a href="#box-left-forms"><?php echo $this->__("Profile");?></a></li>
                     <li><a href="#box-left-other"><?php echo $this->__("Chnage Password");?></a></li>
                <?php endif;?>
            </ul>
        </div>
        
        <div id="box-left-forms">
            <div class="form">
                <div class="fields">
                    <div class="field">
                        <div class="label">
                            <label for="input"><?php echo $this->__("First Name:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Admin][f_name]",$adminlist['f_name'],array("id"=>"f_name","class"=>"large check_notempty","longdesc"=>"Please enter  first name"));?>
                        </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[Admin][l_name]",$adminlist['l_name'],array("id"=>"l_name","class"=>"large check_notempty","longdesc"=>"Please enter last name"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="email"><?php echo $this->__("Email:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Admin][email]",$adminlist['email'],array("id"=>"email","class"=>"large check_email","longdesc"=>"Please enter email address"));?>
                        </div>
                    </div>
                    <?php if($action == 'add'):?>
                    <div class="field">
                        <div class="label">
                            <label for="username"><?php echo $this->__("Username:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Admin][username]",$adminlist['username'],array("id"=>"username","class"=>"large check_notempty","longdesc"=>"Please enter a valid user name"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="password"><?php echo $this->__("Password:");?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->passwordTag("data[Admin][password]",'',array("id"=>"password","class"=>"large check_notempty","longdesc"=>"Please enter with combination of A-Za-z0-9"));?>
                        </div>
                    </div>
                    <?php endif;?>
                    <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[Admin][status]",array("Active"=>"Active","Pending"=>"Pending"),$adminlist['status'],array('id'=>'status'));?>
                        </div>
                    </div>
                    <div class="fields">
                        <div class="field">
                            <div class="label label-textarea">
                                        <label for="description"><?php echo $this->__("Description:");?></label>
                                    </div>
                            <div class="textarea">
                                <?php echo App::load("Helper/Html")->textareaTag("data[Admin][description]",$adminlist['description'],array("id"=>"description","class"=>"textarea"));?>
                            </div>
                        </div>
                    </div>
                    <div class="buttons">
                        <input type="submit" name="data[Admin][submit]" onclick="jQuery('.pass_chng_ref').val('')" value="Save" /> <div class="message msgrightalign"></div>
                    </div>
                </div>
            </div>
        </div>
        <?php if($action != 'add'):?>
        <div id="box-left-other">
            <div class="form">
                <div class="fields">
                    <div class="field">
                        <div class="label">
                            <label for="l_name"><?php echo $this->__("New Password:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->passwordTag("data[Admin][newpassword]",'',array("id"=>"newpassword","class"=>"pass_chng_ref large check_notempty","longdesc"=>"Please enter last name"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="l_name"><?php echo $this->__("Confirm New Password:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->passwordTag("data[Admin][cnewpassword]",'',array("id"=>"cnewpassword","class"=>"pass_chng_ref large check_notempty","longdesc"=>"Please enter last name"));?>
                        </div>
                    </div>
                    <div class="field">
                        <div class="label">
                            <label for="l_name"><?php echo $this->__("Reason:"); ?></label>
                        </div>
                        <div class="input">
                            <?php echo App::load("Helper/Html")->inputTag("data[Admin][reason]",'',array("id"=>"reason","class"=>"pass_chng_ref large check_notempty","longdesc"=>"Please enter last name"));?>
                        </div>
                    </div>
                    <div class="buttons">
                        <input type="submit" name="data[Admin][changepasw]"  value="Update"/> <div class="message msgrightalign"></div>
                    </div>
                </div>
            </div>
        </div>
        <?php endif;?>
    </div>

    <div class="box box-right">
        <div class="title">
            <h5><?php echo $this->__("Acess Control Limit");?></h5>
        </div>
        <?php if( strtolower($adminlist['type']) != 'super'):?>
        <div class="form">
            <?php echo App::Module('Acl')->AdminNavList($adminlist['id']);?>
            <p>            
            <?php App::Module('Hook')->getHandler('acl','register_detail_acl',$adminlist,'display'); ?></p>
        </div>
        <?php else:?>
            <h4><?php echo $this->__("Inportant");?></h4>
            <p>
                <?php echo $this->__("This is super admin has access in all tab.");?><br />
                <?php echo(implode(', ',$admin_nav_def)); ?>
                </p>
        <?php endif;?>
    </div>
</form>

<!-- -- VALIDATION DATA -- -->
<?php  App::Helper('JavaScript')->setAjax(array("debug"=>false,"autoHide"=>false))->appForm('form');?>

<?php else: ?>
    <?php App::Helper('Toolbar')->setTitle("View Administrators")->setBtnBack()->Render(array('code'=>'admin_list_view_top'));?>
    <?php if(!empty($adminlist["data"])): ?>
        <?php
            $Grid = App::Module('DataGrid');
            $Grid->setHeader(array('#','Login Name', 'Name', 'Email','Status','Type','Options'));
            $Grid->setFooter($adminlist['paging_str']);
            foreach($adminlist["data"] as $key => $val){
                if((strtolower($val['type'])=='super')){
                    $Grid->addRow((($adminlist["page"] - 1) * $this->get_config('default_pagination') + $key + 1),$val['username'],"{$val['f_name']} {$val['l_name']}", $val['email'], $val['status'], $val['type'], App::load("Helper/Html")->linkTag($this->baseurl('/admin/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")));
                }
                else{
                    $Grid->addRow((($adminlist["page"] - 1) * $this->get_config('default_pagination') + $key + 1),$val['username'],"{$val['f_name']} {$val['l_name']}", $val['email'], $val['status'], $val['type'], App::load("Helper/Html")->linkTag($this->baseurl('/admin/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")) . '&nbsp;' . 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'=>'Admin','class'=>'link_delete icon', 'title'=>'Admin_' . $val['id'])));
                }
            }
            $Grid->Render();
        ?>
    <?php else: ?>
        <?php echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found')); ?>
    <?php endif; ?>
    <?php App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'admin_list_view_bottom'));?>
<?php endif; ?>