changed git call from https to git readonly
[atutor.git] / mods / job_board / include / classes / Employer.class.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2009                                                                                         */
6 /* Adaptive Technology Resource Centre / Inclusive Design Institute        */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
9 /* This program is free software. You can redistribute it and/or           */
10 /* modify it under the terms of the GNU General Public License             */
11 /* as published by the Free Software Foundation.                                           */
12 /***********************************************************************/
13 // $Id$
14
15 class Employer{
16         var $id;                        //employer id
17         var $username;      //employer's username
18         var $name;                      //employer name
19         var $company;           //company name
20         var $description;   //description of this employer
21         var $email;                     //employer's email
22         var $website;           //company's website
23         var $last_login;    //last login date
24         var $approval_state;//approval state
25
26         //constructor
27         function Employer($id){
28                 global $db;
29
30                 $id = intval($id);
31                 $this->id = $id;
32                 
33                 $sql = 'SELECT username, employer_name, email, company, description, website, last_login, approval_state FROM '.TABLE_PREFIX."jb_employers WHERE id=$id";
34                 $result = mysql_query($sql, $db);
35                 if ($result){
36                 $row = mysql_fetch_assoc($result);
37
38                 $this->name             = $row['employer_name'];
39                 $this->username = $row['username'];
40                 $this->company  = $row['company'];
41                 $this->description      = $row['description'];
42                 $this->email    = $row['email'];
43                 $this->website  = $row['website'];
44                 $this->last_login = $row['last_login'];
45                 $this->approval_state = $row['approval_state'];
46                 }
47         }
48         
49         function getId(){
50                 return $this->id;
51         }
52
53         function getUsername(){
54             return $this->username;
55     }
56
57         function getName(){
58                 return $this->name;
59         }
60         
61         function getEmail(){
62                 return $this->email;
63         }
64
65         function getCompany(){
66                 return $this->company;
67         }
68         
69         function getDescription(){
70             return $this->description;
71     }
72
73         function getWebsite(){
74                 return $this->website;
75         }
76         
77         function getLastLogin(){
78             return $this->last_login;
79     }
80     
81     function getApprovalState(){
82         return $this->approval_state;
83     }
84
85         /**
86          * Set the approval state value
87          * @param       int             Approval state, check constants.inc.php
88          * @return      null
89          */
90         function setApprovalState($state){
91                 global $addslashes, $db;
92                 
93                 //change this if the approval_state has more than 3 values in the constant file
94                 $state = (intval($state) > 2)?AT_JB_STATUS_UNCONFIRMED:intval($state);
95
96                 $sql = 'UPDATE '.TABLE_PREFIX."jb_employers SET approval_state='$state' WHERE id=".$this->id;
97                 mysql_query($sql, $db);
98         }
99
100
101         /**
102          * Update the employer profile.  
103          *
104          * @param       string          employer's name
105          * @param       string          company's name
106          * @param       string          employer's email
107          * @param       string          employer's website.
108      * @param   string      employer's description
109          * @return      null
110          */
111          function updateProfile($name, $company, $email, $website, $description){
112                 global $addslashes, $db;
113                 $name = $addslashes($name);
114                 $company = $addslashes($company);
115                 $email = $addslashes($email);
116                 $website = $addslashes($website);
117         $description = $addslashes($description);
118                 
119                 $sql = 'UPDATE '.TABLE_PREFIX."jb_employers SET employer_name='$name', company='$company', email='$email', website='$website', description='$description' WHERE id=".$this->id;
120                 $result = mysql_query($sql, $db);
121                 if ($result){
122                         return true;
123                 } 
124                 return false;
125          }
126          
127          /**
128           * Update password 
129           * @pass   string      SHA1 encrpted password, length=40
130           */
131          function updatePassword($pass){
132             global $addslashes, $db;
133             $pass = $addslashes($pass);
134           
135             //if password is empty, or not encrypted, quit
136             if ($pass=='' || strlen($pass)!=40){
137                 return;
138         }
139         
140             $sql = 'UPDATE '.TABLE_PREFIX."jb_employers SET password='$pass' WHERE id=".$this->id;
141             mysql_query($sql, $db);
142          }
143
144         /**
145          * Simple authentication.  
146          *
147          * @return      Boolean         True if is an employer with the valid id.  False otherwise.
148          * @precondition                User has been authenticated via the login page.
149          * @access public
150          */
151         function authenticate(){
152                 if(isset($_SESSION['jb_employer_id']) && $_SESSION['jb_employer_id'] > 0){
153                         return true;
154                 }
155                 return false;
156         }
157 }
158 ?>