-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleModel.php
More file actions
executable file
·151 lines (128 loc) · 3.51 KB
/
Copy pathScheduleModel.php
File metadata and controls
executable file
·151 lines (128 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* This is model class
*/
class ScheduleModel {
/*private $sOdooUrl = 'http://localhost:8069';
private $sOdooDb = 'Scheduling';
private $sOdooUsername = "admin";
private $sOdooPassword = "12345";*/
private $sOdooUrl = 'http://127.0.0.1:8069';
private $sOdooDb = 'odoo_db';
private $sOdooUsername = "admin";
private $sOdooPassword = "Luca2017";
private $iOdooUID;
private $aOdooUser;
private $aOdooProfile;
private $sBaseUrl = "/index.php";
private $aBookingDetail = array();
public function __construct() {
}
public function getBaseUrl() {
return $this->sBaseUrl;
}
public function getOdooUser() {
if ($this->aOdooUser) {
return $this->aOdooUser;
} else if( isset( $_SESSION['odooUser'] ) ) {
$this->aOdooUser = $_SESSION['odooUser'];
return $this->aOdooUser;
}
return false;
}
public function setOdooUser($aUser) {
$this->aOdooUser = $aUser;
$_SESSION['odooUser'] = $aUser;
}
public function updateInfo( $aInfo ) {
$oUser = $this->getOdooUser();
if( $oUser ) {
$this->aOdooUser['credit'] = $aInfo['credit'];
$this->aOdooUser['status'] = $aInfo['status'];
$this->aOdooUser['start'] = $aInfo['start'];
$this->aOdooUser['end'] = $aInfo['end'];
$this->setOdooUser($this->aOdooUser);
return true;
}
return false;
}
public function getBookingDetails() {
if( $this->aBookingDetail ) {
return $this->aBookingDetail;
}
if( empty( $this->aBookingDetail ) && $_SESSION['bookingDetails'] ) {
$this->aBookingDetail = $_SESSION['bookingDetails'];
return $this->aBookingDetail;
}
return false;
}
public function setBookingDetails( $aDetails ) {
$this->aBookingDetail = $aDetails;
$_SESSION['bookingDetails'] = $aDetails;
}
public function executeOdooCommand($sModel, $sAction, $aFilters, $aParams = array()) {
if (!$this->getOdooUID()) {
return false;
}
try {
$oModels = ripcord::client("$this->sOdooUrl/xmlrpc/2/object");
$vRes = $oModels->execute_kw(
$this->sOdooDb, $this->iOdooUID, $this->sOdooPassword, $sModel, $sAction, $aFilters, $aParams
);
if( array_key_exists( 'faultCode', $vRes) ) {
return false;
}
return $vRes;
} catch( Exception $e) {
return false;
}
}
public function setSessionToken($bNew = true) {
if (!$bNew) {
unset($_SESSION['loginToken']);
unset($_SESSION['odooUser']);
return true;
}
$sGuid = uniqid();
if ($sGuid) {
$_SESSION['loginToken'] = $sGuid;
$this->bLoginFailed = false;
return true;
}
return false;
}
public function getSessionToken() {
if (isset($_SESSION['loginToken'])) {
return $_SESSION['loginToken'];
}
return false;
}
public function getOdooUID() {
if ($this->iOdooUID) {
return $this->iOdooUID;
}
require_once('plugins/ripcord/ripcord.php');
$oCommon = ripcord::client("$this->sOdooUrl/xmlrpc/2/common");
$this->iOdooUID = $oCommon->authenticate(
$this->sOdooDb, $this->sOdooUsername, $this->sOdooPassword, array()
);
error_log(var_export($this->iOdooUID, true));
if ($this->iOdooUID) {
return $this->iOdooUID;
}
return false;
}
public function setOdooProfile( $vVal ) {
$this->aOdooProfile = $vVal;
}
public function getOdooProfile() {
if( $this->aOdooProfile ) {
return $this->aOdooProfile;
}
return false;
}
public function toCurrency( $fNumber ) {
$fNumber = number_format( $fNumber, 2 );
return (string) $fNumber . "€";
}
}