-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
executable file
·1691 lines (1302 loc) · 53.2 KB
/
db.php
File metadata and controls
executable file
·1691 lines (1302 loc) · 53.2 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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?
$HTTP_POST_VARS=$GLOBALS['_POST'];
$HTTP_GET_VARS=$GLOBALS['_GET'];
require_once('db2.php');
function startsWith($haystack, $needle)
{
return !strncmp($haystack, $needle, strlen($needle));
}
function user_exist($user, $db2){
$stmt = $db2->prepare("select * from tree_users_social where identity=:identity");
$stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
$stmt->execute( array( ':identity' => $user["identity"] ) );
$user_exist = $stmt->fetch();
if($user_exist["user_id"] && $curl = curl_init()) {
$stmt = $db2->prepare("select * from tree_users where id=:user_id");
$stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
$stmt->execute( array( ':user_id' => $user_exist["user_id"] ) );
$user_exist = $stmt->fetch();
$path = "https://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];
$path = str_replace("login.php", "oauth2/token.php", $path);
curl_setopt($curl, CURLOPT_URL, $path);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
$md5email = $user_exist["md5email"];
$passw = $user_exist["password"];
$params_post = 'grant_type=password&username='.$md5email.
'&password='.$passw.
'&client_id=4tree_web'.
'&client_secret=4tree_passw'.
'&secret=888';
// echo $params_post;
curl_setopt($curl, CURLOPT_POSTFIELDS, "test_it_now=1&".$params_post);
$out = curl_exec($curl);
curl_close($curl);
//echo $params_post."<br>".$out;
// echo $out;
return $out;
} else {
return "";
}
}
function create_new_user($user, $db2){
//print_r($user);
$stmt = $db2->prepare("select * from tree_users where email=:email");
$stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
$stmt->execute( array( ':email' => $user["email"] ) );
$user_exist = $stmt->fetch();
if($user_exist) {
echo "<center style='margin: 90px;position: absolute;width: 300px;left: 50%;margin-left: -150px;color: #CCC;font-size: 10px;'>Пользователь с электронным адресом: ".$user["email"]." уже зарегистирован. Нажмите: 'забыл пароль' внизу страницы. Войдите и связывайте соц.сервис в настройках.</center>";
} else {
$sql11 = "INSERT INTO `tree_users` SET
`fio` = :fio,
`mobilephone` = :mobilephone,
`email` = :email,
`md5email` = :md5email,
`confirm_email` = :confirm_email,
`password` = :password,
`reg_date` = :reg_date,
`foto` = :foto,
`frends` = :frends,
`female` = :female,
`lastvisit` = :lastvisit";
// echo $sql11;
$last_name = $user["last_name"]?$user["last_name"]." ":"";
$fio = $last_name.$user["first_name"];
$newpassword = substr(md5($user["identity"]."pass_990"),3,10);
$code = '4tree_'.substr(md5($email),5,10);
$values11 = array(
":fio" => $fio,
":mobilephone" => $user["mobilephone"]?$user["mobilephone"]:"",
":email" => $user["email"]?$user["email"]:"",
":md5email" => $user["email"]?md5($user["email"]."990990"):"",
":confirm_email" => $user["email"]?$code:"",
":password" => md5($newpassword),
":reg_date" => date("Y-m-d H:i:s"),
":foto" => $user["photo"]?$user["photo"]:"",
":frends" => ",11,",
":female" => 1,
":lastvisit" => 0
);
$query1 = $db2->prepare($sql11);
$query1->execute($values11);
$last_user_id = $db2->lastInsertId();
if(!$last_user_id) {
echo "Ошибка регистрации";
return false;
}
push(array("am"),array('type' => "new_user_social", 'from' => $fpk_id, 'txt' => "Новый пользователь через соц.сети <b title='".addslashes($values11)."'>параметры</b>"));
if(stristr($user["email"],"@")) {
//отправляю сгенерированный пароль
$tree="<font color='#214516'>4</font><font color='#244918'>t</font><font color='#356d23'>r</font><font color='#42872c'>e</font><font color='#57b33a'>e</font>";
mail($user["email"],'Вы только что зарегистрировались на 4tree.ru',"<font size='3em'> Привет,<br><br>Вы только что зарегистрировались на ".$tree.".<br>Чтобы подтвердить регистрацию, пожалуйста, пройдите по ссылке ниже:<br><a href='https://4tree.ru/?confirm=".$code."'><font size=5em><b>https://4tree.ru/home/?confirm=".$code."</b></font></a></font><br><br><br>Желаю успехов в делах, ваш ".$tree.".<br><br><br>PS: Между прочим, вы регистрировались через ".$user["network"].",<br>поэтому мы сгенерировали вам пароль сами: <h2>".$newpassword."</h2>",
"From: 4tree-mailer <noreply@4tree.ru>\r\nContent-type: text/html; charset=UTF-8;\r\n");
mail("eugene.leonar@gmail.com",'Регистрация через соц.сеть',"<font size='3em'> Привет,<br><br>Вы только что зарегистрировались на ".$tree.".<br>Чтобы подтвердить регистрацию, пожалуйста, пройдите по ссылке ниже:<br><a href='https://4tree.ru/home/?confirm=".$code."'><font size=5em><b>https://4tree.ru/home/?confirm=".$code."</b></font></a></font><br><br><br>Желаю успехов в делах, ваш ".$tree.".<br><br><br>PS: Между прочим, вы регистрировались через ".$user["network"].",<br>поэтому мы сгенерировали вам пароль сами: <b>".$newpassword."</b>",
"From: 4tree-mailer <noreply@4tree.ru>\r\nContent-type: text/html; charset=UTF-8;\r\n");
}
mySaveToSocial($last_user_id, $user, $db, $db2);
$sql = "";
$sql["id"] = 6570;//6570
mySelectBranch($sql,1,$last_user_id);
user_exist($user, $db2);
}
// echo "<hr>$last_id<hr>";
//2. create in tree_users
}
function mySaveToSocial($last_user_id,$user,$db,$db2) {
//1. save_to tree_users_social
$sql11 = "INSERT INTO `tree_users_social` SET
`user_id` = :user_id,
`network` = :network,
`identity` = :identity,
`uid` = :uid,
`bdate` = :bdate,
`country` = :country,
`profile` = :profile,
`last_name` = :last_name,
`first_name` = :first_name,
`city` = :city,
`photo_big` = :photo_big,
`photo` = :photo,
`session_md5` = :session_md5,
`fio` = :fio,
`email` = :email,
`sex` = :sex";
// echo $sql11;
$values11 = array(
":user_id" => $last_user_id,
":network" => $user["network"],
":identity" => $user["identity"],
":uid" => $user["uid"],
":bdate" => $user["bdate"],
":country" => $user["country"],
":profile" => $user["profile"],
":last_name" => $user["last_name"],
":first_name" => $user["first_name"],
":city" => $user["city"],
":photo_big" => $user["photo_big"],
":photo" => $user["photo"],
":session_md5"=> $user["session_md5"],
":fio" => $user["fio"],
":email" => $user["email"],
":sex" => $user["sex"],
":session_md5" => md5($user["identity"]."990990")
);
$query1 = $db2->prepare($sql11);
$query1->execute($values11);
$last_id = $db2->lastInsertId();
return $last_id;
}
function push ($cids, $message) {
//return true;
/*
* $cids - ID канала, либо массив, у которого каждый элемент - ID канала
* $text - сообщение, которое необходимо отправить
*/
$c = curl_init();
$url = 'http://4do.me/pub?id=';
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
if (is_array($cids)) {
foreach ($cids as $v) {
curl_setopt($c, CURLOPT_URL, $url.$v);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($message));
$r = curl_exec($c);
}
} else {
curl_setopt($c, CURLOPT_URL, $url.$cids);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($message));
$r = curl_exec($c);
}
curl_close($c);
return $r;
}
if (time()<1346331456) $read=1;
else $read=0;
function myCreateRecord($sql, $new_parent, $new_user) {
$sqlnews="INSERT INTO `tree` SET
user_id = '$new_user',
position = '".$sql["position"]."',
node_icon = '".$sql["node_icon"]."',
adddate = '".$sql["adddate"]."',
changetime = '".now1()."',
title = '".addslashes($sql["title"])."',
parent_id = '".$new_parent."',
text = '".addslashes($sql["text"])."',
old_id = '-8'";
$result = mysql_query_my($sqlnews);
$id = mysql_insert_id();
// echo "<li>parent_id=".$new_parent." | n_i=$id | title=<b>".$sql["title"]."</b></li>";
return $id;
};
function now1()
{
// return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()).valueOf();
return (integer)(microtime(true)*1000);
}
function mySelectBranch($sql2, $new_parent, $new_user) {
$sqlnews = "SELECT * FROM tree WHERE del=0 AND user_id=11 AND parent_id=".$sql2["id"];
// echo $sqlnews."<hr>";
$result = mysql_query_my($sqlnews);
$i=0;
// echo "<ol>";
while (@$sql = mysql_fetch_array($result))
{
// echo "sdfdfsd";
$id = myCreateRecord($sql, $new_parent, $new_user);
// echo $id." - ";
mySelectBranch($sql, $id, $new_user);
}
// echo "</ol>";
}
function username($shortname) {
global $config;
return 'Вецель Евгений';
}
function brand($shortname) {
global $config;
return 'Peugeot';
}
//Верхнее меню для всех страниц ФПК
function menu() {
return '
<a href="?r=clients">Клиенты</a> | <a href="?r=stat">Статистика</a> |
<a href="file://Aldebaran/pgt-autosales$/" target="_blank">Папка ОП</a></div>';
}
//////////////////////////////////////////////////////////////////////////////
//Вывод таблицы с шаблоном $theme
function displayNewsAll($theme,$sqlnews) {
global $config,$r,$iii,$rrr;
$r=$GLOBALS['_GET']['r'];
$result = mysql_query_my($sqlnews);
$TXT='';
$iii=0;
while ($sql = mysql_fetch_object ($result))
{
$TXT.=displayNewsEntry($sql, $theme, $detail="no");
if($rrr==5) $iii+=mod_rrcost($sql);
}
return $TXT;
}
//Вывод одной строки
function displayNewsEntry($sql, $theme, $detail="no") {
global $config,$topic;
$fullbox=str_replace("\n","", str_replace("\r\n","", implode("", file($config['themedir'].$theme))));
preg_match_all("/#(.*)#/U",$fullbox,$matches);
for ($i=0; $i<count($matches[0]); $i++) {
$func_name="mod_".strtolower($matches[1][$i]);
if (function_exists($func_name)) {
$tag=call_user_func($func_name,$sql,66,$detail);
$fullbox=str_replace($matches[0][$i],$tag,$fullbox);
} else {
echo "Func $func_name not exists<br>\n";
}
}
if(stristr($theme,'json'))
{
static $jsonReplaces = array(
array("\\", "/", "\t", "\b", "\f", "'"),
array('\\\\', '\\/', '\\t', '\\b', '\\f', "`"));
$fullbox = str_replace("'", "`", $fullbox);
$fullbox = preg_replace("/\r?\n/", "\\n", $fullbox);
}
return $fullbox;
}
function UpdateClients()
{
global $HTTP_POST_VARS,$config,$client;
$sqlnews="UPDATE 1_clients SET
fio='".$HTTP_POST_VARS['fio']."',
phone1='".$HTTP_POST_VARS['phone1']."',
phone2='".$HTTP_POST_VARS['phone2']."',
phone3='".$HTTP_POST_VARS['phone3']."',
phone4='".$HTTP_POST_VARS['phone4']."',
phone11='".$HTTP_POST_VARS['phone11']."',
phone22='".$HTTP_POST_VARS['phone22']."',
phone33='".$HTTP_POST_VARS['phone33']."',
phone44='".$HTTP_POST_VARS['phone44']."',
adress='".$HTTP_POST_VARS['adress']."',
comment='".$HTTP_POST_VARS['comment']."',
birthday='".$HTTP_POST_VARS['birthday']."'
WHERE id=".$client;
if ($read==0) $result = mysql_query_my($sqlnews);
}
function UpdateDo()
{
global $HTTP_POST_VARS,$config,$do,$GLOBALS;
$sqlnews="
UPDATE `1_do` SET
`manager` = '".$HTTP_POST_VARS['SELECTMANAGER']."',
`date1` = '".$HTTP_POST_VARS['DATE1']."',
`date2` = '".$HTTP_POST_VARS['DATE2']."',
`text` = '".$HTTP_POST_VARS['TEXT']."',
`comment` = '".$HTTP_POST_VARS['DOCOMMENT']."',
`checked` = '".$HTTP_POST_VARS['DOCHECKED']."',
`type` = '".$HTTP_POST_VARS['DOTYPE']."',
`host` = '".$HTTP_POST_VARS['DOHOST']."',
`important` = '".$HTTP_POST_VARS['DOIMPORTANT']."',
`remind` = '".$HTTP_POST_VARS['DOREMIND']."',
`changed` = '".gmdate("Y-m-d H:i:s",cheltime(time()))."'
WHERE `id` ='".$do."' LIMIT 1";
if ($read==1) $result = mysql_query_my($sqlnews);
}
function AddDo($client,$Type,$did)
{
global $HTTP_POST_VARS,$config,$fpk_user,$fpk_brand;
if ($did==1) $d=gmdate("Y-m-d H:i:s",cheltime(time()));
else $d="0000-00-00 00:00:00";
$ddd = gmdate("Y-m-d H:i:s",cheltime(time()));
$sqlnews="
INSERT INTO `1_do` ( `id` , `client` , `brand` , `manager` , `date1` , `date2` , `text` , `comment` , `checked` , `type` , `host` , `important` , `repeat` , `remind` , `created` , `changed` , `starred` , `hostcheck` , `shablon` )
VALUES (
'', '".$client."', '".$fpk_brand."', '".$fpk_user."', '".$ddd."', '".$ddd."', '".$Type."', '', '".$d."', '".$Type."', '".$fpk_user."', '50', '', '0000-00-00 00:00:00', '".$ddd."', '0000-00-00 00:00:00', '', '0000-00-00 00:00:00', '')
";
// echo $sql;
// $fp = fopen('its2.txt', "w");
// @fwrite($fp, 'rrr='.$fpk_user);
// fclose($fp);
//echo $sqlnews;
if ($read==0) $result = mysql_query_my($sqlnews);
$sqlnews="SELECT max(id) maxid FROM `1_do`";
$result = mysql_query_my($sqlnews);
$sql = mysql_fetch_object ($result);
return($sql->maxid);
}
function AddClient($Manager)
{
global $HTTP_POST_VARS,$config,$fpk_user,$fpk_brand;
if(stristr($Manager,'<')) $Manager='Все';
$sqlnews="
INSERT INTO `1_clients` ( `id` , `fio` , `comment` , `phone1` , `phone2` , `phone3` , `phone4` , `date` , `adress` , `birthday` , `brand` , `manager` )
VALUES (
'', '', '', '', '', '', '', '".gmdate("Y-m-d",cheltime(time()))."', '', '1978-00-00', '".$fpk_brand."', '".$Manager."'
);
";
$result = mysql_query_my($sqlnews);
$sqlnews="SELECT max(id) maxid FROM `1_clients`";
$result = mysql_query_my($sqlnews);
$sql = mysql_fetch_object ($result);
return($sql->maxid);
}
function DeleteClient($id)
{
global $HTTP_POST_VARS, $config;
$sqlnews="DELETE FROM 1_do WHERE client=".$id." LIMIT 100";
$result = mysql_query_my($sqlnews);
$sqlnews="DELETE FROM 1_clients WHERE id=".$id." LIMIT 1";
$result = mysql_query_my($sqlnews);
}
function DeleteDo($id)
{
global $HTTP_POST_VARS, $config;
$sqlnews="DELETE FROM 1_do WHERE id=".$id." LIMIT 1";
$result = mysql_query_my($sqlnews);
}
////Поля таблицы 1_clients
function mod_fio($sql) { return str_replace('"',"`",$sql->fio); }
function mod_typetime($sql)
{
global $HTTP_GET_VARS;
if ($sql->typetime=='') return '';
else
{
$tm=''.date("H:i",strtotime($sql->typetime)).' - ';
$alldate=$HTTP_GET_VARS['ALLDate'];
if (strlen($alldate)==7) $tm=''.date("d.m",strtotime($sql->typetime)).' - ';
// $™ = strlen($alldate);
return $tm;
}
}
function mod_fioshort($sql)
{
$name=str_replace('"',"`",$sql->fio);
$explodeName = explode(" ", $name);
$lng=0;$txt='';
for ($i=0; $i<count($explodeName); $i++) {
$lng += strlen($explodeName[$i]);
if($lng<74) $txt.=$explodeName[$i].' ';
else { $txt.='…'; break; }
}
return $txt;
}
function mod_fioshort2($sql)
{
$name=str_replace('"',"`",$sql->fio);
$explodeName = explode(" ", $name);
$name = $explodeName[0];
$name .= ' '.mb_substr($explodeName[1], 0, 1,'utf-8').'.';
return $name;
}
function mod_commercial($sql)
{
return $sql->commercial;
}
function mod_status($sql)
{
return $sql->status;
}
function mod_cost($sql)
{
return $sql->cost;
}
function mod_files($sql)
{
if ($sql->files==0) return '';
else return $sql->files;
}
function mod_filesopacity($sql)
{
if ($sql->files==0) return 0;
else return 1;
}
function mod_rcost($sql)
{
$cost = (integer)($sql->cost/1000);
if ($cost==0)
{
$sqlnews="SELECT cost FROM `1_models` WHERE id=".$sql->model;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
$cost = '~'.(integer)($sql2->cost)/1000;
if ($sql2->cost<300000) $cost='~444';
}
return $cost.' т.р.';
}
function mod_rrcost($sql)
{
$cost = (integer)($sql->cost/1000);
if ($cost==0)
{
$sqlnews="SELECT cost FROM `1_models` WHERE id=".$sql->model;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
$cost = (integer)($sql2->cost)/1000;
if ($sql2->cost<300000) $cost=444;
}
return $cost;
}
function mod_vin($sql)
{
return $sql->vin;
}
function mod_model($sql)
{
$sqlnews="SELECT model FROM `1_models` WHERE id=".$sql->model;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
return $sql2->model;
}
function mod_modelfio($sql)
{
$sqlnews="SELECT short FROM `1_models` WHERE id=".$sql->fio;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
return $sql2->short;
}
function mod_modelid($sql)
{
$sqlnews="SELECT id FROM `1_models` WHERE id=".$sql->model;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
return $sql2->id;
}
function mod_modelshort($sql)
{
$sqlnews="SELECT short FROM `1_models` WHERE id=".$sql->model;
$result = mysql_query_my($sqlnews);
@$sql2 = mysql_fetch_object ($result);
if ($sql2->short=='') return mod_model2($sql).'?';
return $sql2->short;
}
function mod_statusshort($sql)
{
if ($sql->status[0]=='5') return '..';
if ($sql->status[0]=='?') return ' ?';
if ($sql->status[0]=='+') return ' +';
else
{
return '';
}
}
function mod_statuscolor($sql)
{
if ($sql->status[0]=='+') return '#516F8F';
else
{
if ($sql->status[0]=='1') { $cl1=0.2; $cl2=0.24; }
if ($sql->status[0]=='2') { $cl1=0.5; $cl2=0.54; }
if ($sql->status[0]=='3') { $cl1=0.8; $cl2=0.84; }
if ($sql->status[0]=='4') { $cl1=0.9; $cl2=0.94; }
if ($sql->status[0]=='5') { $cl1=0.95; $cl2=0.96; }
if ($sql->status[0]=='?') { $cl1=1; $cl2=1; }
if ($sql->status=='') { $cl1=1; $cl2=1; }
return "-webkit-gradient(linear, right top, left top, color-stop($cl1, #2b365a), color-stop($cl2, #516F8F));";
//return '#516F8F';
}
}
function mod_model2($sql)
{
$name=str_replace('"',"`",$sql->comment);
$name = explode(" ", $name);
$name = $name[0];
return mb_substr($name, 0, 8,'utf-8');;
}
function mod_id($sql) { return $sql->id; }
function mod_phone1($sql) { return str_replace('"',"`",$sql->phone1); }
function mod_phone2($sql) { return str_replace('"',"`",$sql->phone2); }
function mod_phone3($sql) { return str_replace('"',"`",$sql->phone3); }
function mod_phone4($sql) { return str_replace('"',"`",$sql->phone4); }
function mod_phone11($sql) { return str_replace('"',"`",$sql->phone11); }
function mod_phone22($sql) { return str_replace('"',"`",$sql->phone22); }
function mod_phone33($sql) { return str_replace('"',"`",$sql->phone33); }
function mod_phone44($sql) { return str_replace('"',"`",$sql->phone44); }
function mod_email($sql) { return str_replace('"',"`",$sql->email); }
function mod_pas1($sql) { return str_replace('"',"`",$sql->pas1); }
function mod_pas2($sql) { return str_replace('"',"`",$sql->pas2); }
function mod_pas3($sql) { return str_replace('"',"`",$sql->pas3); }
function mod_pas4($sql) { return d(str_replace('"',"`",$sql->pas4)); }
function mod_carpets($sql) { if($sql->carpets==1) return 'checked'; }
function mod_mudguard($sql) { if($sql->mudguard==1) return 'checked'; }
function mod_tech_1($sql) { if($sql->tech_1==1) return 'checked'; }
function mod_tech_2($sql) { if($sql->tech_2==1) return 'checked'; }
function mod_tires($sql) { if($sql->tires==1) return 'checked'; }
function mod_client_adress($sql) { return $sql->client_adress; }
function d($mydate)
{
$answer = explode('-',$mydate);
return $answer[2].'-'.$answer[1].'-'.$answer[0];
}
function mod_clientbirthday($sql) { return d(str_replace('"',"`",$sql->clientbirthday)); }
function mod_prepay($sql) { return str_replace('"',"`",$sql->prepay); }
function mod_date_contract($sql) { return d(str_replace('"',"`",$sql->date_contract)); }
function mod_adress($sql) { return mb_substr(str_replace('"',"`",$sql->adress),0,55,'utf-8'); }
function mod_manager($sql) { return $sql->manager; }
function mod_groupby($sql)
{
global $groupby;
if ($groupby=='status') $name=";";
if ($groupby=='icon') $name=" - желание";
if ($groupby=='icon2') $name=" - Вероятность выдачи в этом месяце";
if ($groupby=='manager') $name="";
if ($groupby!='') $group = $sql->$groupby;
return $group.' '.$name.'';
}
function mod_creditmanager($sql) { return $sql->creditmanager; }
function mod_showmanager($sql) {
$explodeName = explode(" ", $sql->manager);
return '['.$explodeName[0].']';
}
function mod_icon($sql) { return $sql->icon; }
function mod_icon2($sql) { return $sql->icon2; }
function mod_d1($sql)
{
if ($sql->dg=='0000-00-00 00:00:00') return '';
return showdatedif($sql->dg);
}
function mod_d2($sql)
{
if ($sql->zv=='0000-00-00 00:00:00') $dat=$sql->vz;
else $dat = $sql->zv;
if ($dat=='0000-00-00 00:00:00') return '';
return showdatedif($dat);
}
function showdatedif($mydate)
{
$long="";
$dd=(int)( ((gmstrtotime($mydate))-cheltime(gmmktime()) )/60/60*10)/10;
if (($dd>24) or ($dd<-24))
{
$dd=(int)($dd/24);
$long="long";
if ($dd>=0) $days="+ ".$dd." дн";
else
$days=$dd." дн";
}
else
{
if ($dd>=0) $days="+ ".$dd." ч";
else
$days=$dd." ч";
}
return $days;
}
function mod_nextdo($sql)
{
$sqlnews="SELECT date2, checked FROM `1_do` WHERE client=".$sql->id." and checked='0000-00-00 00:00:00' ORDER by date2 LIMIT 1;";
$result = mysql_query_my($sqlnews);
$sql1 = mysql_fetch_object ($result);
$dat = showdatejson($sql1->date2,$sql1);
if(!$sql1->date2)
{
if((($sql->out)!="0000-00-00 00:00:00") AND ($sql->dg)!="0000-00-00 00:00:00") return '{"classdo":"shortdatedid2","date":"OUT","days":"Расторг"}';
if(($sql->out)!="0000-00-00 00:00:00") return '{"classdo":"shortdatedid","date":"OUT","days":"OUT"}';
return '{"classdo":"shortdatedid","date":"Нет следующего действия","days":""}';
}
return '{"classdo":"'.$dat[0].'","date":"'.$dat[1].'","days":"'.$dat[2].'"}';
}
function mod_birthday($sql) { return $sql->birthday; }
function mod_comment($sql) { return stripcslashes(str_replace('"',"`",$sql->comment)); }
function mod_alldo($sql) {
global $fpk_brand;
//Задаем даныне для отображения дел
$Date = "%"; // Даты для фильтра или %-отобразить все Даты "2010-10-04 -> 2010-10-09,2010-10-12 -> 2010-10-14,2010-10-19,2010-10-21 -> 2010-10-22,2010-10-28"
$Manager = "%"; // Имя менеджера "JohnWecel"
$Clientid = $sql->id; // Номер клиента "23"
$Did = 0; // 1-скрывать ли выполненные дела (0=все, 1=скрывать выполненные, 2=только выполненные)
$Template = "fpk-do-acordion.php"; // Шаблон
$What = "Show"; // Что делать - Show, Edit, Add, Delete
$Host = "%"; // Кто поручил дело
$Search = "%"; // Что ищем "%Курган%
$SearchField = array ("1_clients.fio","1_clients.phone1","1_clients.phone2","1_clients.phone3","1_clients.phone4","1_do.comment","1_do.text","1_clients.comment","1_clients.adress","1_clients.birthday");
$Brand = $fpk_brand; // Какой бренд
$Type = "%"; // Тип действия
$Hide = 1; // 1=показывать скрытые дела
$Order = "Order by DATE2 DESC"; //Сортировка
return ShowMeDo(
$Date,
$Manager,
$sql->id,
$Did,
$Template,
$What,
$Host,
$Search,
$SearchField,
$Brand,
$Type,
$Hide,
$Order
);
}
////Поля таблицы 1_do
function mod_text($sql) { return str_replace('"',"`",$sql->text); }
function mod_slave($sql) { return $sql->slave; }
function mod_showslave($sql)
{
$name = explode(' ',$sql->slave);
if ($sql->manager == $sql->slave) return '';
else
return '[Исполнитель: '.$name[0].']';
}
function mod_host($sql)
{
$explodeName = explode(" ", $sql->host);
$host=$explodeName[0];
if( $sql->host == $sql->manager ) $host='';
if ($host=='') return '';
else
return str_replace('"',"`",' [Поручил: '.$host.']');
}
//Права доступа для редактирования клиента
function mod_readonly($sql)
{
global $fpk_user, $fpk_job;
$job = (stristr($fpk_job,'иректор')) || (stristr($fpk_job,'уковод') ) || (stristr($fpk_job,'тарш') ) || (stristr($fpk_job,'редитн') || (stristr($fpk_job,'Администратор')));
//$job = false;
//Если дело добавил админстратор, то не разрешать менеджерам удалять клиента
if ((!$job) && ($sql->tmp=='Администратор')) return 'readonly';
if (($fpk_user == $sql->manager) || ($sql->manager=='Все') || $job ) return '';
else return 'readonly';
}
function mod_doreadonly($sql)
{
global $fpk_user, $fpk_job;
if (($sql->type=='Тест-драйв') and ($fpk_job=="Администратор")) return '';
if (($sql->type=='Кредит') and ($fpk_job=="Кредитный эксперт")) return '';
if (($sql->type=='Выдача')) return '';
if (($sql->type=='Подготовка') and ($fpk_job=="Логист")) return '';
if ($sql->checked != '0000-00-00 00:00:00')
if ( (time() - strtotime($sql->checked))/(60*60*24) > 3 ) $timeover = true;
else $timeover = false;
$job = (stristr($fpk_job,'иректор')) || (stristr($fpk_job,'уковод')) || (stristr($fpk_job,'тарш'));
//$job = false;
if ( ((($sql->host == $fpk_user) || ($sql->slave == $fpk_user)) && !$timeover) || $job ) return '';
else return 'readonly';
}
function mod_textshort($sql)
{
return mb_substr(str_replace('"',"`",$sql->text), 0, 50,'utf-8');
}
function mod_type($sql) { return $sql->type; }
function mod_docomment($sql) { return str_replace('"',"`",$sql->docomment); }
function mod_clientid($sql) { return $sql->client; }
function mod_doid($sql) { return $sql->doid; }
function mod_dodate($sql) { return $sql->date1; }
function mod_dodate2($sql) { return $sql->date2; }
function mod_dochecked($sql) { return $sql->checked; }
function mod_important($sql) { return $sql->important; }
function mod_doremind($sql) { return $sql->remind; }
function mod_docreated($sql) { return $sql->created; }
function mod_dochanged($sql) { return $sql->changed; }
function mod_hostcheck($sql) { return $sql->hostcheck; }
/*function mod_doclient($sql)
{
global $config,$client;
$sqlnews="select * from `1_clients` WHERE id='".$sql->client."'";
$result = mysql_query_my($sqlnews);
@$sql1 = mysql_fetch_object ($result);
if (@$client=='') return '<a href="./index.php?r=client_edit&client='.$sql1->id.'" title="'.$sql1->phone1.'">'.$sql1->fio.'</a>';
}
*/
function mod_doclientshort($sql)
{
global $config,$client;
$sqlnews="select fio from `1_clients` WHERE id='".$sql->client."'";
$result = mysql_query_my($sqlnews);
@$sql1 = mysql_fetch_object ($result);
$name=$sql1->fio;
$explodeName = explode(" ", $sql1->fio);
for ($i=0; $i<count($explodeName); $i++) {
if ($i==0) $name = $explodeName[$i];
if ($i==1) $name.= ' '.$explodeName[$i];
}
return $name;
}
function mod_doclientmini($cl)
{
global $config,$client;
$sqlnews="select fio from `1_clients` WHERE id='".$cl."'";
$result = mysql_query_my($sqlnews);
@$sql1 = mysql_fetch_object ($result);
return $sql1->fio;
}
function mod_doeditclient($sql)
{
global $config;
$sqlnews="select id,phone1,fio from `1_clients` WHERE id='".$sql->client."'";
$result = mysql_query_my($sqlnews);
@$sql1 = mysql_fetch_object ($result);
return '<a href="./home/index.php?r=client_edit&client='.$sql1->id.'" title="'.$sql1->phone1.'">'.$sql1->fio.'</a>';
}
function mod_date2json($sql)
{
//return array ($class.$long, $mydate, $days);
$dat = showdatejson($sql->date2,$sql);
return $dat[2];
}
function mod_date1json($sql)
{
//return array ($class.$long, $mydate, $days);
$dat = showdatejson($sql->date2,$sql);
return '{"classdo":"'.$dat[0].'","date":"'.$dat[1].'","days":"'.$dat[2].'"}';
}
function mod_date1($sql)
{
return showdate($sql->date2,$sql);
}
function mod_checkcolor($sql)
{
if ($sql->checked=="0000-00-00 00:00:00") return "black";
else return "8b8b8b";
}
function mod_inputdonejson($sql)
{
if ($sql->checked=="0000-00-00 00:00:00")
return '{"idd":"'.$sql->doid.'","name":"Выполнить"}';
else return '{"idd":"'.$sql->doid.'","name":"Снять выполнение"}';
}