Ignore:
Timestamp:
Oct 31, 2014 2:55:30 PM (11 years ago)
Author:
quyenla
Message:

collaborator

Location:
pro-violet-viettel/sourcecode
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/admin/controllers/collaborator.php

    r363 r366  
    5252
    5353    public function addCollaborator() {
    54        
     54        $result['success'] = 0;
    5555        $result = array();
    5656        $input = $this->input->post();
    5757        $this->load->model('collabolator_model');
    58         $this->collabolator_model->insert($input);
    59         $result['success'] = 1;
     58        if (strlen($input['full_name'])==0)
     59        {
     60            $result['errors'][]="Tên cộng tác viên khÃŽng được để trống";
     61        }
     62        if (strlen($input['login_name'])==0)
     63        {
     64            $result['errors'][]="Tên đăng nhập khÃŽng được để trống";
     65        }
     66        else
     67        {
     68            if ($this->collabolator_model->isExist(array('field'=>'login_name','value'=>$input['login_name'])))
     69            {
     70                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
     71            }
     72        }
     73        if (strlen($input['cellphone'])==0)
     74        {
     75            $result['errors'][]="Số điện thoại khÃŽng được để trống";
     76        }
     77        else
     78        {
     79            if ($this->collabolator_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'])))
     80            {
     81                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
     82            }
     83        }
     84        if (strlen($input['passwd'])==0)
     85        {
     86            $result['errors'][]="Mật khẩu khÃŽng được để trống";
     87        }
     88        if ($input['passwd'] != $input['passwd2'])
     89        {
     90            $result['errors'][]="Mật khẩu khÃŽng trùng nhau";
     91        }
     92        if (!isset($result['errors']))
     93        {
     94            unset($input['passwd2']);
     95            $input['activated']=1;
     96            $input['created_time']=date("Y-m-d H:i:s");
     97            $input['updated_time']=date("Y-m-d H:i:s");
     98            $this->load->model('collabolator_model');
     99            $this->collabolator_model->insert($input);
     100            $result['success'] = 1;
     101        }
     102
     103       
    60104        echo json_encode($result);
    61105    }
  • pro-violet-viettel/sourcecode/application/modules/admin/models/collabolator_model.php

    r360 r366  
    44{
    55       
    6         protected $table_name = 'tblcollabolator';
     6        protected $table_name = 'tblcollaborator';
    77        protected $id_name = 'id';
    88
     
    1313        function getCollaborator($data)
    1414        {
    15             $sql="SELECT * FROM tblcollaborator";
     15            $sql="SELECT * FROM ".$this->table_name;
    1616            $data['keyword']='';
    1717
    1818            if ($data['keyword'])
    1919            {
    20             $sql.=" WHERE (full_name LIKE '%".$data['keyword']."%' OR login_name LIKE '%".$data['keyword']."%')";
     20            $sql.=" WHERE (full_name LIKE '%".$data['keyword']."%' OR login_name LIKE '%".$data['keyword']."%') ";
    2121            }
    22             return $this->db->query($sql." LIMIT ".$data['start'].", ".$data['perpage']."")->result_array();
     22            return $this->db->query($sql." ORDER BY id DESC LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
    2323
     24        }
     25        function isExist($data)
     26        {
     27            $sql="SELECT COUNT(id) as total FROM ".$this->table_name." WHERE ".$data['field']." = '".$data['value']."' LIMIT 1";
     28            if ($this->db->query($sql)->row_array()['total']==1)
     29            {
     30                return true;
     31            }
     32            else
     33            {
     34                return false;
     35            }
     36           
    2437        }
    2538        function countCollaborator($data)
    2639        {
    27             $sql="SELECT COUNT(id) as total FROM tblcollaborator";
     40            $sql="SELECT COUNT(id) as total FROM ".$this->table_name;
    2841            if (isset($data['keyword']))
    2942            {
    30             $sql.=" WHERE (full_name LIKE '%".$data['keyword']."%' OR login_name LIKE '%".$data['keyword']."%')";
     43            $sql.=" WHERE (full_name LIKE '%".$data['keyword']."%' OR login_name LIKE '%".$data['keyword']."%') ";
    3144            }
    3245
  • pro-violet-viettel/sourcecode/application/modules/admin/views/collaborator/index.php

    r359 r366  
    131131                        <div class="help-block"> </div>
    132132                    </div>
     133                    <div class="form-group">
     134                        <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> Mật khẩu </label>
     135
     136                        <div class="col-sm-9">
     137                            <span class="input-icon">
     138                                <input type="password" name="passwd2" id="form-field-2" placeholder="Nhập lại mật khẩu">
     139                                <i class="icon-lock blue"></i>
     140                            </span>
     141                        </div>
     142                        <div class="help-block"> </div>
     143                    </div>
    133144
    134145                    <div class="space-4"></div>
    135 
     146                    <div class="form-group errors" id="add_user">
     147                       
     148                    </div>
    136149                    <div class="clearfix form-actions">
    137150                        <div class="col-md-offset-3 col-md-9">
  • pro-violet-viettel/sourcecode/assets/js/admin/collaborator.js

    r360 r366  
    77})(jQuery);
    88$(".btn#add_user").click(function ()
    9 {
     9{$(".errors#add_user").html("");
    1010    $.ajax({
    1111                url: "cong_tac_vien/them",
     
    1414                success: function (data, textStatus, jqXHR)
    1515                {
    16                     // $result = jQuery.parseJSON(data);
    17                     $("#content").html(data);
    18                     init_page();
    19 
     16                    $result = jQuery.parseJSON(data);
     17                    if ($result.success == "1")
     18                    {   
     19                    filter();
     20                    $('#addUser').modal('hide');
     21                    }
     22                    else
     23                    {
     24                       
     25                        for(var i =0;i < $result.errors.length;i++)
     26                        {
     27                          var er= $result.errors[i];
     28                          $(".errors#add_user").append("<div class='error'>"+er+"</div>");
     29                        }
     30                    }
     31                   
    2032                },
    21                 error: function (jqXHR, textStatus, errorThrown)
    22                 {
    23                     $(".ajaxloading").hide();
    24                 }
     33               
    2534            });
    2635       
Note: See TracChangeset for help on using the changeset viewer.