forked from makeyourcloud/myc-vtiger-customer-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal.php
executable file
·391 lines (262 loc) · 13.6 KB
/
portal.php
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
/* * *******************************************************************************
* The content of this file is subject to the MYC Vtiger Customer Portal license.
* ("License"); You may not use this file except in compliance with the License
* The Initial Developer of the Original Code is Proseguo s.l. - MakeYourCloud
* Portions created by Proseguo s.l. - MakeYourCloud are Copyright(C) Proseguo s.l. - MakeYourCloud
* All Rights Reserved.
* ****************************************************************************** */
class Router
{
/*****************************************************************************
* Function: Router::start()
* Description: This function intercept the $_REQUEST parameters and call the requested action
* ****************************************************************************/
public static function start()
{
global $avmod;
$targetmodule=$_REQUEST['module'];
$targetaction=$_REQUEST['action'];
//Get a list of available module for this user
$params = array($_SESSION["loggeduser"]['id']);
$avmod=$GLOBALS["sclient"]->call('get_modules',$params);
//if no target module specified set HelpDesk as the default index module
if(!isset($targetmodule) || $targetmodule=="") $targetmodule="HelpDesk";
//if a download for a file is requested call the function to retrieve the desired file
if(isset($_REQUEST['downloadfile']) && $_REQUEST['downloadfile']==="true") User::download_file();
//Check if the requested module is Available
if(!in_array($targetmodule, $avmod)) $targetmodule="HelpDesk";//die("Not Autorized!");
//Require the base module class
require_once("modules/Module/index.php");
//if isset a specific file and a specific class for the requested module include the extended class and create the object
if(file_exists("modules/".$targetmodule."/index.php")) require_once("modules/".$targetmodule."/index.php");
if(class_exists($targetmodule)) $mod=new $targetmodule();
else $mod=new BaseModule($targetmodule);
//if is pesent a target id show the corrispondent entity else show a list of entities for the target module
if(isset($_REQUEST['ticketid'])) $mod->detail($_REQUEST['ticketid']);
else if(isset($_REQUEST['productid'])) $mod->detail($_REQUEST['productid']);
else if(isset($_REQUEST['faqid'])) $mod->detail($_REQUEST['faqid']);
else if(isset($_REQUEST['id'])) $mod->detail($_REQUEST['id']);
else if($targetmodule=="HelpDesk" && $targetaction=="new") $mod->create_new();
else $mod->get_list();
//if there is a request for change password call the modal again and show the request resault
if(isset($GLOBALS["opresult"]) && $GLOBALS["opresult"]!="") echo "<script> $(function(){ $('#changePassModal').modal('show'); })</script>";
}
}
class Template
{
/*****************************************************************************
* Function: Template::display()
* Description: This function receive 3 parameters the module wich you want to display, the data array to pass to the view
* and the view name (the name of the view file).
* ****************************************************************************/
public static function display($module,$data,$viewname)
{
//If a parameter theme is specified in the REQUEST, the theme will be setted as requestes, else the default theme will be loaded
if(isset($_REQUEST['theme']) && $_REQUEST['theme']!="" && is_dir("themes/".$_REQUEST['theme']))
$_SESSION["portal_theme"]=$_REQUEST['theme'];
if(isset($_SESSION["portal_theme"])) $currtheme=$_SESSION['portal_theme'];
else $currtheme=$GLOBALS["portal_theme"];
//Require common header and menu files
require_once("themes/".$currtheme."/header.php");
require_once("themes/".$currtheme."/menu.php");
//Fallback cascade theme inclusion, first check if is present a specified view for the current module in the current theme folder
if(file_exists("themes/".$currtheme."/modules/".$module."/".$viewname.".php"))
require_once("themes/".$currtheme."/modules/".$module."/".$viewname.".php");
//else check if is present a specified DEFAULT view for the current module in the current module folder
else if(file_exists("modules/".$module."/layouts/".$viewname.".php"))
require_once("modules/".$module."/layouts/".$viewname.".php");
//else check if is present a specified DEFAULT view for COMMON modules in the current theme module folder
else if(file_exists("themes/".$currtheme."/modules/Module/".$viewname.".php"))
require_once("themes/".$currtheme."/modules/Module/".$viewname.".php");
//else require the DEFAULT view for COMMON modules in the comon module folder
else require_once("modules/Module/layouts/".$viewname.".php");
//Require common footer file
require_once("themes/".$currtheme."/footer.php");
}
}
class Language
{
/*****************************************************************************
* Function: Language::translate()
* Description: This function return the translated string, if it is found in the language file, else it will return the term as
* prompted
* ****************************************************************************/
public static function translate($term,$lang=false)
{
$lang=$_SESSION["loggeduser"]['language'];
if(file_exists("language/".$lang.".lang.php")) include("language/".$lang.".lang.php");
if(isset($app_strings[$term])) return $app_strings[$term];
else return $term;
}
}
class User
{
/*****************************************************************************
* Function: User::check_login()
* ****************************************************************************/
public static function check_login()
{
global $opresult;
//ADDED TO ENABLE THEME SWITCHING
if(isset($_REQUEST['theme']) && $_REQUEST['theme']!="" && is_dir("themes/".$_REQUEST['theme']))
$_SESSION["portal_theme"]=$_REQUEST['theme'];
if(isset($_SESSION["portal_theme"])) $currtheme=$_SESSION['portal_theme'];
else $currtheme=$GLOBALS["portal_theme"];
//********************************
if(isset($_REQUEST['logout'])) {
session_unset();
$_SESSION["portal_theme"]=$currtheme;
}
if(!isset($_SESSION['loggeduser']) || $_SESSION["loggeduser"]=="ERROR") {
$login=false;
if(isset($_REQUEST["email"]) && isset($_REQUEST["pass"])) $login=User::portal_login($_REQUEST["email"],$_REQUEST["pass"]);
if(isset($_REQUEST["email"]) && isset($_REQUEST["forgot"])) $lres=User::forgot_password($_REQUEST["email"]);
if(!$login || $login[0]=="INVALID_USERNAME_OR_PASSWORD") {
if($login[0]=="INVALID_USERNAME_OR_PASSWORD") $loginerror= $login[0];
if(isset($lres) && $lres=="ERROR") $loginerror="The Email you Request is not in our system!";
else if(isset($lres) && $lres=="SUCCESS") $successmess="We have send an Email containing your Password at the requested Address!";
if(file_exists("themes/".$currtheme."/login.php")) require_once("themes/".$currtheme."/login.php");
else require_once("themes/default/login.php");
session_unset();
die();
}
}
else User::portal_login($_SESSION['loggeduser']['user_name'],$_SESSION['loggeduser']['user_password']);
if(isset($_SESSION['loggeduser']) && isset($_REQUEST['fun']) && $_REQUEST['fun']=="changepassword")
$GLOBALS["opresult"]=User::change_password();
}
/*****************************************************************************
* Function: User::forgot_password()
* ****************************************************************************/
function forgot_password($email){
$params = array('email' => $email);
$result = $GLOBALS["sclient"]->call('send_mail_for_password', $params);
if(strpos($result,'false')!==false) return "ERROR";
else return "SUCCESS";
}
/*****************************************************************************
* Function: User::portal_login()
* ****************************************************************************/
function portal_login($email,$password){
$params = array('user_name' => "$email",
'user_password'=>"$password",
'version' => "6.0.1");
$result = $GLOBALS["sclient"]->call('authenticate_user', $params);
if(isset($result[0]['id'])){
if(isset($_REQUEST['lang']) && file_exists("language/".$_REQUEST['lang'].".lang.php")) $tlang = $_REQUEST['lang'];
else if(isset($_SESSION["loggeduser"]['language'])) $tlang=$_SESSION["loggeduser"]['language'];
else $tlang = "it_it";
$_SESSION["loggeduser"] = $result[0];
$_SESSION["loggeduser"]['language'] = $tlang;
}
return $result;
}
/*****************************************************************************
* Function: User::change_password()
* Parameters: $_REQUEST Array
* Description: This function is derived from the original change_password function
* written in the Vtiger Customer Portal by the Vtiger Team
* ****************************************************************************/
//Added for My Settings - Save Password
function change_password($version="6.0.0")
{
global $client;
$customer_id = $_SESSION["loggeduser"]['id'];
$customer_name = $_SESSION["loggeduser"]['user_name'];
$oldpw = trim($_REQUEST['old_password']);
$newpw = trim($_REQUEST['new_password']);
$confirmpw = trim($_REQUEST['confirm_password']);
$params = array('user_name'=>"$customer_name",'user_password'=>"$oldpw",'version'=>"$version",'login'=>'false');
$result = $GLOBALS["sclient"]->call('authenticate_user',$params);
$sessionid = $_SESSION["loggeduser"]['sessionid'];
if(isset($result) && isset($result[0]['user_password']) && $oldpw == $result[0]['user_password'])
{
if(strcasecmp($newpw,$confirmpw) == 0)
{
$customerid = $result[0]['id'];
$sessionid = $_SESSION["loggeduser"]['sessionid'];
$params = array(array('id'=>"$customerid", 'sessionid'=>"$sessionid", 'username'=>"$customer_name",'password'=>"$newpw",'version'=>"$version"));
$result_change_password = $GLOBALS["sclient"]->call('change_password',$params);
if($result_change_password[0] == 'MORE_THAN_ONE_USER'){
$errormsg .= 'MORE_THAN_ONE_USER';
}else{
$errormsg .= 'MSG_PASSWORD_CHANGED';
}
}
else
{
$errormsg .= 'MSG_ENTER_NEW_PASSWORDS_SAME';
}
}elseif($result[0] == 'INVALID_USERNAME_OR_PASSWORD') {
$errormsg .= 'LBL_ENTER_VALID_USER';
}elseif($result[0] == 'MORE_THAN_ONE_USER'){
$errormsg .= 'MORE_THAN_ONE_USER';
}
else
{
$errormsg .= 'MSG_YOUR_PASSWORD_WRONG';
}
return $errormsg;
}
/*****************************************************************************
* Function: User::download_file()
* Parameters: $_REQUEST Array
* Description: This function is derived from the original download function
* written in the Vtiger Customer Portal by the Vtiger Team
* ****************************************************************************/
function download_file(){
$filename = $_REQUEST['filename'];
$fileType = $_REQUEST['filetype'];
//$fileid = $_REQUEST['fileid'];
$filesize = $_REQUEST['filesize'];
//Added for enhancement from Rosa Weber
if($_REQUEST['module'] == 'Invoice' || $_REQUEST['module'] == 'Quotes')
{
$id=$_REQUEST['id'];
$block = $_REQUEST['module'];
$params = array('id' => "$id", 'block'=>"$block", 'contactid'=>$_SESSION["loggeduser"]['id'],'sessionid'=>$_SESSION["loggeduser"]['sessionid']);
$fileContent = $GLOBALS["sclient"]->call('get_pdf', $params);
$fileType ='application/pdf';
$fileContent = $fileContent[0];
$filesize = strlen(base64_decode($fileContent));
$filename = "$block.pdf";
}
else if($_REQUEST['module'] == 'Documents')
{
$id=$_REQUEST['id'];
$folderid = $_REQUEST['folderid'];
$block = $_REQUEST['module'];
$params = array('id' => "$id", 'folderid'=> "$folderid",'block'=>"$block", 'contactid'=>$_SESSION["loggeduser"]['id'],'sessionid'=>$_SESSION["loggeduser"]['sessionid']);
$result = $GLOBALS["sclient"]->call('get_filecontent_detail', $params);
$fileType=$result[0]['filetype'];
$filesize=$result[0]['filesize'];
$filename=html_entity_decode($result[0]['filename']);
$fileContent=$result[0]['filecontents'];
}
else
{
$ticketid = $_REQUEST['ticketid'];
$fileid = $_REQUEST['fileid'];
//we have to get the content by passing the customerid, fileid and filename
$customerid = $_SESSION["loggeduser"]['id'];
$sessionid = $_SESSION["loggeduser"]['sessionid'];
$params = array(array('id'=>$customerid,'fileid'=>$fileid,'filename'=>$filename,'sessionid'=>$sessionid,'ticketid'=>$ticketid));
$fileContent = $GLOBALS["sclient"]->call('get_filecontent', $params);
$fileContent = $fileContent[0];
$filesize = strlen(base64_decode($fileContent));
}
// : End
//we have to get the content by passing the customerid, fileid and filename
$customerid = $_SESSION["loggeduser"]['id'];
$sessionid = $_SESSION["loggeduser"]['sessionid'];
header("Content-type: $fileType");
header("Content-length: $filesize");
header("Cache-Control: private");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Description: PHP Generated Data");
echo base64_decode($fileContent);
exit;
}
}
?>