Хранилища Subversion ant

Редакция

Редакция 549 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
 *  
554 alex-w 5
 *  Codename: ant-ng - generator of sources.list for apt-distributives
304 alex-w 6
 *  http://alex-w.org.ru/p/antng/
7
 *
8
 *  Copyright (c) 2009 Alexander Wolf
9
 *  Dual licensed under the MIT and GNU LGPL licenses.
10
 *  http://alex-w.org.ru/p/antng/license
11
 *
12
 */
13
 
14
class Core {
308 alex-w 15
    protected $db       = NULL;
16
    protected $prefix   = NULL;
313 alex-w 17
    protected $secure   = NULL;    
359 alex-w 18
    protected $cookie   = NULL;
304 alex-w 19
 
463 alex-w 20
    /**
21
     * Конструктор класса Core - ядро генератора
22
     *
23
     * @author Alexander Wolf
24
     * @category Core
25
     *
26
     * @param string $database
27
     * @param string $prefix
28
     * @param object $secure
29
     * @param string $cookie
30
     */
368 alex-w 31
    public function __construct($database, $prefix, $secure, $cookie) {
308 alex-w 32
        $this->db       = $database;
33
        $this->prefix   = $prefix;
359 alex-w 34
        $this->secure   = $secure;
35
        $this->cookie   = $cookie;
307 alex-w 36
    }
37
 
463 alex-w 38
    /**
39
     * Получение данных о настройке
40
     *
41
     * @author Alexander Wolf
42
     * @category Core
43
     *
44
     * @param string $attr
45
     * @return array
46
     */
368 alex-w 47
    public function getOption($attr) {
308 alex-w 48
        $result = array();
315 alex-w 49
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
314 alex-w 50
        $rq =& $this->db->query($query);
308 alex-w 51
        if ($rq->numRows()!=0) {
52
            $rq->fetchInto($element);
53
            $result["ERR"] = 0;
54
            $result["OptValue"] = $element["optvalue"];
55
        } else {
56
            $result["ERR"] = 1;
57
            $result["ERRINFO"] = "Empty result";
58
        }
59
        return $result;
60
    }
61
 
463 alex-w 62
    /**
63
     * Установка данных о настройке
64
     *
65
     * @author Alexander Wolf
66
     * @category Core
67
     *
68
     * @param string $attr
69
     * @param string $value
70
     * @return array
71
     */
368 alex-w 72
    public function setOption($attr, $value) {
359 alex-w 73
        $result = array();
74
 
75
        if ($attr != "passwd") {
76
            $sValue = $this->secure->checkStr($value);
77
        } else {
78
            $sValue = $value;
79
        }
80
 
81
        $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
82
        $rq =& $this->db->query($query);
83
        if (PEAR::isError($this->db)) {
84
            $result["ERR"] = 1;
85
            $result["ERRINFO"] = $this->db->getMessage();
86
        } else {
87
            $result["ERR"] = 0;
88
        }
89
 
90
        return $result;
91
    }
92
 
463 alex-w 93
    /**
94
     * Создание настройки
95
     *
96
     * @author Alexander Wolf
97
     * @category Core
98
     *
99
     * @param string $attr
100
     * @param string $value
101
     * @return array
102
     */
368 alex-w 103
    public function addOption($attr, $value) {
359 alex-w 104
        $result = array();
105
        $sValue = $this->secure->checkStr($value);
106
 
107
        $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
108
        $rq =& $this->db->query($query);
109
        if (PEAR::isError($this->db)) {
110
            $result["ERR"] = 1;
111
            $result["ERRINFO"] = $this->db->getMessage();
112
        } else {
113
            $result["ERR"] = 0;
114
        }
115
 
116
        return $result;
117
    }
463 alex-w 118
 
119
    /**
467 alex-w 120
     * Получение и отображение списка дистрибутвов
463 alex-w 121
     *
122
     * @author Alexander Wolf
123
     * @category Core
124
     * @deprecated may be deprecated XXX
125
     *
126
     * @param string $name
127
     * @param string $heads
128
     * @param string $info
129
     * @param string $format
130
     * @return string
131
     */
393 alex-w 132
    public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
315 alex-w 133
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
317 alex-w 134
        $rq =& $this->db->query($query);
315 alex-w 135
        switch ($format) {
136
            case 'html':
394 alex-w 137
                $show  = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
390 alex-w 138
                $show .= "<option value=''>".$info."</option>\n";
315 alex-w 139
                while ($rq->fetchInto($element)) {
140
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
141
                }
317 alex-w 142
                $show .= "</select></fieldset>";
315 alex-w 143
                break;
144
            case 'json':
317 alex-w 145
                $show = '[{value:"",text:"'.$info.'"}';                
315 alex-w 146
                while ($rq->fetchInto($element)) {
147
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
148
                }
149
                $show .= ']';
150
                break;
504 alex-w 151
            case 'innerhtml':
152
                $show = "<select id='".$name."' name='".$name."'>\n";
153
                while ($rq->fetchInto($element)) {
154
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
155
                }
156
                $show .= "</select>";
157
                break;
506 alex-w 158
            case 'list':
159
                $show = "<ul>";
160
                while ($rq->fetchInto($element)) {
546 alex-w 161
                    $show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."' class='edit'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
506 alex-w 162
                }
163
                $show .= "</ul>";
164
                break;
315 alex-w 165
        }
166
        return $show;
167
    }
168
 
463 alex-w 169
    /**
170
     * Получение названия дистрибутива
171
     *
172
     * @author Alexander Wolf
173
     * @category Core
174
     *
175
     * @param integer $distID
176
     * @return array
177
     */
368 alex-w 178
    public function getDistName($distID) {
315 alex-w 179
        $result = array();
180
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
181
        $rq =& $this->db->query($query);
182
        if (PEAR::isError($this->db)) {
183
            $result["ERR"] = 1;
184
            $result["ERRINFO"] = $this->db->getMessage();
185
        } else {
186
            $rq->fetchInto($element);
187
            $result["ERR"] = 0;
188
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
189
        }
190
 
191
        return $result;
192
    }
193
 
463 alex-w 194
    /**
195
     * Получение названия программы, ее версии и описания
196
     *
197
     * @author Alexander Wolf
198
     * @category Core
199
     *
200
     * @param string $attr
201
     * @return string
202
     */
383 alex-w 203
    public function getEngineAttr($attr = 'codename') {
204
        $cname = $this->getOption($attr);
382 alex-w 205
        return $this->secure->checkStr($cname["OptValue"],1);
381 alex-w 206
    }
207
 
463 alex-w 208
    /**
209
     * Получение и отображение списка версий дистрибутива
210
     *
211
     * @author Alexander Wolf
212
     * @category Core
213
     *
214
     * @param string $name
215
     * @param integer $distID
216
     * @param string $format
217
     * @return string
218
     */
509 alex-w 219
    public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') {
316 alex-w 220
        $distname = $this->getDistName($distID);
509 alex-w 221
        if ($distID == 0) {
222
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ORDER BY d.dist_id,v.version ASC";
223
        } else {
224
            $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
225
        }
317 alex-w 226
        $rq =& $this->db->query($query);
315 alex-w 227
        switch ($format) {
228
            case 'html':
394 alex-w 229
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
230
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
315 alex-w 231
                while ($rq->fetchInto($element)) {
316 alex-w 232
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
315 alex-w 233
                }
317 alex-w 234
                $show .= "</select></fieldset>";
315 alex-w 235
                break;
236
            case 'json':
317 alex-w 237
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
315 alex-w 238
                while ($rq->fetchInto($element)) {
316 alex-w 239
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
315 alex-w 240
                }
241
                $show .= ']';
242
                break;
509 alex-w 243
            case 'list':
244
                $show = "<ul>\n";
245
                while ($rq->fetchInto($element)) {
545 alex-w 246
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." &#8220;<em>".$this->secure->checkStr($element["vname"],1)."</em>&#8221;</li>\n";
509 alex-w 247
                }
248
                $show .= "</ul>";
249
                break;
315 alex-w 250
        }
251
        return $show;
252
    }
253
 
463 alex-w 254
    /**
255
     * Получение и отображение списка секций основного (официального) репозитория
256
     *
257
     * @author Alexander Wolf
258
     * @category Core
259
     *
260
     * @param integer $version
261
     * @param string $format
262
     * @return string
263
     */
368 alex-w 264
    public function showBranchesList($version, $format = 'html') {
317 alex-w 265
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
266
        $rq =& $this->db->query($query);
267
        $rq->fetchInto($types);
268
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
269
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
270
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
271
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
272
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
273
        $rq =& $this->db->query($query);
274
        switch ($format) {
275
            case 'html':
276
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
277
                while ($rq->fetchInto($element)) {
493 alex-w 278
                    $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." &mdash; ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n";
317 alex-w 279
                }
280
                $show .= "</fieldset>\n";
281
                break;
282
            case 'json':
283
                //TODO Доделать JSON-вывод списка секций основного репозитория
284
                break;
285
        }
318 alex-w 286
 
287
        return $show;
317 alex-w 288
    }
289
 
463 alex-w 290
    /**
291
     * Получение и отображение списка репозиториев
292
     *
293
     * @author Alexander Wolf
294
     * @category Core
295
     *
296
     * @param integer $version
297
     * @param integer $reptype
298
     * @param string $format
299
     * @return string
300
     */
368 alex-w 301
    public function showRepList($version, $reptype, $format = 'html') {
406 alex-w 302
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
317 alex-w 303
        $rq =& $this->db->query($query);
304
        $rq->fetchInto($types);
305
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
306
        $rq =& $this->db->query($query);
307
        switch ($format) {
308
            case 'html':
309
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
310
                while ($rq->fetchInto($types)) {
320 alex-w 311
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." &mdash; ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
317 alex-w 312
                }
313
                $show .= "</fieldset>\n";
314
                break;
315
            case 'json':
316
                //TODO Доделать JSON-вывод списка репозиториев
317
                break;
318
        }
318 alex-w 319
 
320
        return $show;
317 alex-w 321
    }
322
 
463 alex-w 323
    /**
324
     * Добавление поддержки нового apt-дистрибутива
325
     *
326
     * @author Alexander Wolf
327
     * @category Core
328
     *
329
     * @param string $distname
330
     * @param integer $disttype
331
     * @param string $distua
332
     * @param byte $distlogo
333
     * @return array
334
     */
514 alex-w 335
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 336
        $result = array();
516 alex-w 337
        $sDName = $this->secure->checkStr($distname,1);
321 alex-w 338
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 339
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 340
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 341
 
342
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
343
        $rq =& $this->db->query($query);
344
        if (PEAR::isError($this->db)) {
345
            $result["ERR"] = 1;
346
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 347
        } else {            
321 alex-w 348
            $result["ERR"] = 0;
349
        }
350
 
351
        return $result;
352
    }
353
 
463 alex-w 354
    /**
514 alex-w 355
     * Обновление информации о дистрибутиве
356
     *
357
     * @author Alexander Wolf
358
     * @category Core
359
     *
360
     * @param integer $distID
361
     * @param string $distname
362
     * @param integer $disttype
363
     * @param string $distua
364
     * @param integer $distlogo
365
     * @return array
366
     */
538 alex-w 367
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 368
        $result = array();
369
        $sDID   = $this->secure->checkInt($distID);
516 alex-w 370
        $sDName = $this->secure->checkStr($distname,1);
514 alex-w 371
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 372
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 373
        $sDLogo = $this->secure->checkInt($distlogo);
374
 
538 alex-w 375
        if ($sDLogo!=0) {
376
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
377
        } else {
378
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
379
        }
514 alex-w 380
        $rq =& $this->db->query($query);
381
        if (PEAR::isError($this->db)) {
382
            $result["ERR"] = 1;
383
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 384
        } else {            
514 alex-w 385
            $result["ERR"] = 0;
386
        }
387
 
388
        return $result;
389
    }
390
 
391
    /**
392
     * Удаление информации о дистрибутиве
393
     *
394
     * @author Alexander Wolf
395
     * @category Core
396
     *
397
     * @param integer $distID
398
     * @return array
399
     */
400
    public function dropDistribution($distID) {
401
        $result = array();
402
        $sDID   = $this->secure->checkInt($distID);
403
 
404
        // Удаление дистрибутива
405
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
406
        $rq =& $this->db->query($query);
407
        if (PEAR::isError($this->db)) {
408
            $result["ERR"] = 1;
409
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 410
        } else {            
514 alex-w 411
            $result["ERR"] = 0;
412
        }
413
 
414
        // Удаление версий дистрибутива
415
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
416
        $rq =& $this->db->query($query);
417
        if (PEAR::isError($this->db)) {
418
            $result["ERR"] = 1;
419
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 420
        } else {            
514 alex-w 421
            $result["ERR"] = 0;
422
        }
423
 
424
        return $result;
425
    }
426
 
427
    /**
463 alex-w 428
     * Добавление поддержки новой версии apt-дистрибутива
429
     *
430
     * @author Alexander Wolf
431
     * @category Core
432
     *
433
     * @param integer $distID
434
     * @param integer $version
435
     * @param string $vname
436
     * @param integer $vcodename
437
     * @return array
438
     */
368 alex-w 439
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 440
        $result = array();
463 alex-w 441
        $sDistID    = $this->secure->checkInt($distID);
516 alex-w 442
        $sDVersion  = $this->secure->checkStr($version,1);
443
        $sDVName    = $this->secure->checkStr($vname,1);
444
        $sDVCName   = $this->secure->checkStr($vcodename,1);
356 alex-w 445
 
446
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
447
        $rq =& $this->db->query($query);
448
        if (PEAR::isError($this->db)) {
449
            $result["ERR"] = 1;
450
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 451
        } else {            
356 alex-w 452
            $result["ERR"] = 0;
453
        }
454
 
455
        return $result;
456
    }
358 alex-w 457
 
463 alex-w 458
    /**
514 alex-w 459
     * Редактирование информации о версии дистрибутива
460
     *
461
     * @author Alexander Wolf
462
     * @category Core
463
     *
464
     * @param integer $versionID
465
     * @param string $version
466
     * @param string $vname
467
     * @param string $vcodename
468
     * @return array
469
     */
470
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
471
        $result = array();
472
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 473
        $sDVersion  = $this->secure->checkStr($version,1);
474
        $sDVName    = $this->secure->checkStr($vname,1);
475
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 476
 
477
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
478
        $rq =& $this->db->query($query);
479
        if (PEAR::isError($this->db)) {
480
            $result["ERR"] = 1;
481
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 482
        } else {            
514 alex-w 483
            $result["ERR"] = 0;
484
        }
485
 
486
        return $result;
487
    }
488
 
489
    /**
490
     * Удаление информации о версии дистрибутива
491
     *
492
     * @author Alexander Wolf
493
     * @category Core
494
     *
495
     * @param integer $versionID
496
     * @return array
497
     */
498
    public function dropDistVersion($versionID) {
499
        $result = array();
500
        $sVersID    = $this->secure->checkInt($versionID);
501
 
502
        // Удаление версии дистрибутива
503
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
504
        $rq =& $this->db->query($query);
505
        if (PEAR::isError($this->db)) {
506
            $result["ERR"] = 1;
507
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 508
        } else {            
514 alex-w 509
            $result["ERR"] = 0;
510
        }
511
 
512
        // Удаление репозиториев этой версии дистрибутива
513
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
514
        $rq =& $this->db->query($query);
515
        if (PEAR::isError($this->db)) {
516
            $result["ERR"] = 1;
517
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 518
        } else {            
514 alex-w 519
            $result["ERR"] = 0;
520
        }
521
 
522
        return $result;
523
    }
524
 
525
    /**
463 alex-w 526
     * Отображение типа дистрибутива
527
     *
528
     * @author Alexander Wolf
529
     * @category Core
530
     *
531
     * @param string $name
532
     * @param byte $type
533
     * @return string
534
     */
368 alex-w 535
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 536
        $query = "SELECT * FROM ".$this->prefix."dtype";
537
        $rq =& $this->db->query($query);
538
        $show = "<select name='".$name."' id='".$name."'>\n";
539
        while ($rq->fetchInto($element)) {
347 alex-w 540
            if ($element["type_id"] == $type) {
541
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 542
            } else {
347 alex-w 543
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 544
            }
545
        }
546
        $show .= "</select>";
547
 
548
        return $show;
549
    }
550
 
463 alex-w 551
    /**
552
     * Отображение формы создания и редактирования apt-дистрибутива
553
     *
554
     * @author Alexander Wolf
555
     * @category Core
556
     *
557
     * @param integer $distID
558
     * @return string
559
     */
511 alex-w 560
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 561
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 562
        $sInfo = $this->secure->checkStr($info, 1);
563
        if ($sInfo == "") {
564
            $sInfo = "Дистрибутив";
565
        }
329 alex-w 566
        if ($sDistID != 0) {
567
            // Режим редактирования
568
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
569
            $rq =& $this->db->query($query);
570
            $rq->fetchInto($element);
571
        }
572
 
573
        if ($element["distlogo"] == 1) {
380 alex-w 574
            $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
329 alex-w 575
        } else {
380 alex-w 576
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 577
        }
578
 
511 alex-w 579
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 580
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
581
        $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
518 alex-w 582
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 583
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 584
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 585
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 586
 
587
        return $show;
588
    }
589
 
358 alex-w 590
    // sourses.list
423 alex-w 591
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
592
       //TODO Написать генератор sources.list       
358 alex-w 593
    }
522 alex-w 594
 
463 alex-w 595
    /**
522 alex-w 596
     * Показывает список секций
597
     *
598
     * @author Alexander Wolf
599
     * @category Core
600
     *
601
     * @param string $name
602
     * @param string $actor
603
     * @return string
604
     */
605
    public function showSectionsList($name, $actor) {
606
        $query = "SELECT * FROM ".$this->prefix."section";
607
        $rq =& $this->db->query($query);
608
        $show = "<ul>\n";
609
        while ($rq->fetchInto($element)) {
545 alex-w 610
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sect_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sect_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["secname"],1)."</li>\n";
522 alex-w 611
        }
612
        $show .= "</ul>";
613
 
614
        return $show;
615
    }
616
 
523 alex-w 617
    /**
618
     * Вывод формы редактирования/добавления секций
619
     *
620
     * @author Alexander Wolf
621
     * @category Core
622
     *
623
     * @param integer $sectionID
624
     * @param string $info
625
     * @return string
626
     */
627
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 628
        $sSectID = $this->secure->checkInt($sectionID);
629
        $sInfo = $this->secure->checkStr($info, 1);
630
        if ($sInfo == "") {
631
            $sInfo = "Секция";
632
        }
633
        if ($sSectID != 0) {
634
            // Режим редактирования
635
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
636
            $rq =& $this->db->query($query);
637
            $rq->fetchInto($element);
638
        }
639
 
640
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
641
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
642
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
643
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
644
 
645
        return $show;
646
    }
647
 
648
    /**
523 alex-w 649
     * Обновление информации о секции
650
     *
651
     * @author Alexander Wolf
652
     * @category Core
653
     *
654
     * @param integer $sectionID
655
     * @param string $sname
656
     * @param string $sinfo
657
     * @return array
658
     */
659
    public function updateSection($sectionID, $sname, $sinfo = "") {
660
        $result = array();
661
        $sSectID    = $this->secure->checkInt($sectionID);
662
        $sSName     = $this->secure->checkStr($sname,1);
663
        $sSInfo     = $this->secure->checkStr($sinfo,1);
664
 
665
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
666
        $rq =& $this->db->query($query);
667
        if (PEAR::isError($this->db)) {
668
            $result["ERR"] = 1;
669
            $result["ERRINFO"] = $this->db->getMessage();
670
        } else {
671
            $result["ERR"] = 0;
672
        }
673
 
674
        return $result;
675
    }
676
 
677
    /**
678
     * Удаление информации о секции
679
     *
680
     * @author Alexander Wolf
681
     * @category Core
682
     *
683
     * @param integer $sectionID
684
     * @return array
685
     */
686
    public function dropSection($sectionID) {
687
        $result = array();
688
        $sSectID    = $this->secure->checkInt($sectionID);
689
 
690
        // Удаление секции
691
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
692
        $rq =& $this->db->query($query);
693
        if (PEAR::isError($this->db)) {
694
            $result["ERR"] = 1;
695
            $result["ERRINFO"] = $this->db->getMessage();
696
        } else {
697
            $result["ERR"] = 0;
698
        }
699
 
700
        return $result;
701
    }
702
 
703
    /**
704
     * Добавление новой секции
705
     *
706
     * @author Alexander Wolf
707
     * @category Core
708
     *
709
     * @param string $sname
710
     * @param string $sinfo
711
     * @return array
712
     */
713
    public function addSection($sname, $sinfo = "") {
714
        $result = array();
715
        $sSName = $this->secure->checkStr($sname,1);
716
        $sSInfo = $this->secure->checkStr($sinfo,1);
717
 
718
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
719
        $rq =& $this->db->query($query);
720
        if (PEAR::isError($this->db)) {
721
            $result["ERR"] = 1;
722
            $result["ERRINFO"] = $this->db->getMessage();
723
        } else {
724
            $result["ERR"] = 0;
725
        }
726
 
727
        return $result;
728
    }
729
 
730
    /**
539 alex-w 731
     * Показывает список подписей
732
     *
733
     * @author Alexander Wolf
734
     * @category Core
735
     *
736
     * @param string $name
737
     * @param string $actor
738
     * @return string
739
     */
740
    public function showSignsList($name, $actor) {
741
        $query = "SELECT * FROM ".$this->prefix."signs";
742
        $rq =& $this->db->query($query);
743
        $show = "<ul>\n";
744
        while ($rq->fetchInto($element)) {
545 alex-w 745
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sign_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sign_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["sname"],1)."</li>\n";
539 alex-w 746
        }
747
        $show .= "</ul>";
748
 
749
        return $show;
750
    }
751
 
752
    /**
753
     * Вывод формы редактирования/добавления подписей
754
     *
755
     * @author Alexander Wolf
756
     * @category Core
757
     *
758
     * @param integer $sectionID
759
     * @param string $info
760
     * @return string
761
     */
762
    public function showSignsForm($signID = 0, $info = "") {
763
        $sSignID = $this->secure->checkInt($signID);
764
        $sInfo = $this->secure->checkStr($info, 1);
765
        if ($sInfo == "") {
766
            $sInfo = "Подписи";
767
        }
768
        if ($sSignID != 0) {
769
            // Режим редактирования
770
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
771
            $rq =& $this->db->query($query);
772
            $rq->fetchInto($element);
773
        }
774
 
775
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
776
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
777
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
778
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
779
 
780
        return $show;
781
    }
782
 
783
    /**
784
     * Обновление информации о секции
785
     *
786
     * @author Alexander Wolf
787
     * @category Core
788
     *
789
     * @param integer $sectionID
790
     * @param string $sname
791
     * @param string $sinfo
792
     * @return array
793
     */
794
    public function updateSign($signID, $sname, $sinfo = "") {
795
        $result = array();
796
        $sSignID    = $this->secure->checkInt($signID);
797
        $sSName     = $this->secure->checkStr($sname,1);
798
        $sSInfo     = $this->secure->checkStr($sinfo,1);
799
 
800
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
801
        $rq =& $this->db->query($query);
802
        if (PEAR::isError($this->db)) {
803
            $result["ERR"] = 1;
804
            $result["ERRINFO"] = $this->db->getMessage();
805
        } else {
806
            $result["ERR"] = 0;
807
        }
808
 
809
        return $result;
810
    }
811
 
812
    /**
813
     * Удаление информации о подписи
814
     *
815
     * @author Alexander Wolf
816
     * @category Core
817
     *
818
     * @param integer $sectionID
819
     * @return array
820
     */
540 alex-w 821
    public function dropSign($signID) {
539 alex-w 822
        $result = array();
823
        $sSignID    = $this->secure->checkInt($signID);
824
 
825
        // Удаление подписи
826
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
827
        $rq =& $this->db->query($query);
828
        if (PEAR::isError($this->db)) {
829
            $result["ERR"] = 1;
830
            $result["ERRINFO"] = $this->db->getMessage();
831
        } else {
832
            $result["ERR"] = 0;
833
        }
834
 
835
        return $result;
836
    }
837
 
838
    /**
540 alex-w 839
     * Добавление новой подписи
539 alex-w 840
     *
841
     * @author Alexander Wolf
842
     * @category Core
843
     *
844
     * @param string $sname
845
     * @param string $sinfo
846
     * @return array
847
     */
540 alex-w 848
    public function addSign($sname, $sinfo = "") {
539 alex-w 849
        $result = array();
850
        $sSName = $this->secure->checkStr($sname,1);
851
        $sSInfo = $this->secure->checkStr($sinfo,1);
852
 
540 alex-w 853
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 854
        $rq =& $this->db->query($query);
855
        if (PEAR::isError($this->db)) {
856
            $result["ERR"] = 1;
857
            $result["ERRINFO"] = $this->db->getMessage();
858
        } else {
859
            $result["ERR"] = 0;
860
        }
861
 
862
        return $result;
863
    }
540 alex-w 864
 
539 alex-w 865
    /**
463 alex-w 866
     * Проверка пароля (из формы авторизации)
867
     *
868
     * @author Alexander Wolf
869
     * @category Core
870
     *
871
     * @param string $word
872
     * @return array
873
     */
368 alex-w 874
    public function checkSign($word) {
359 alex-w 875
        $result = array();
876
 
877
        $sHash = $this->secure->encryptStr($word);
878
        $pwd   = $this->getOption("passwd");
879
        if ($sHash == $pwd["OptValue"]) {
880
            $result["ERR"] = 0;
881
            $result["Location"] = "manager.php";
882
            setcookie($this->cookie, $sHash);
883
        } else {
884
            $result["ERR"] = 1;
885
            $result["ERRINFO"] = "Password not valid";
368 alex-w 886
            $result["Location"] = "manager.php?error=1";
359 alex-w 887
        }
888
 
889
        return $result;
358 alex-w 890
    }
357 alex-w 891
 
463 alex-w 892
    /**
893
     * Проверка пароля (из cookies)
894
     *
895
     * @author Alexander Wolf
896
     * @category Core
897
     *
898
     * @param string $hash
899
     * @return array
900
     */
368 alex-w 901
    public function checkCookieSign($hash) {
359 alex-w 902
        $result = array();
903
 
904
        $pwd = $this->getOption("passwd");
905
        if ($hash == $pwd["OptValue"]) {
906
            $result["ERR"] = 0;
907
        } else {
908
            $result["ERR"] = 1;
909
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 910
            $result["Location"] = "manager.php";
359 alex-w 911
        }
912
 
913
        return $result;
914
    }
915
 
463 alex-w 916
    /**
917
     * Форма ввода пароля
918
     *
919
     * @author Alexander Wolf
920
     * @category Core
921
     *
922
     * @return string
923
     */
368 alex-w 924
    public function showSigninForm() {
425 alex-w 925
        $show  = "<div id='regform'>";
926
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 927
        $show .= "<fieldset><legend>Пароль</legend>\n";
928
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 929
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 930
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 931
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 932
 
933
        return $show;
934
    }
935
 
463 alex-w 936
    /**
937
     * Обновление пароля
938
     *
939
     * @author Alexander Wolf
940
     * @category Core
941
     *
942
     * @param string $word1
943
     * @param string $word2
944
     * @return array
945
     */
368 alex-w 946
    public function updatePassword($word1, $word2) {
359 alex-w 947
        $result = array();
948
 
949
        if ($word1 == $word2) {
950
            $sWord = $this->secure->encryptStr($word1);
951
            $r = $this->setOption("passwd", $sWord);
952
            $result = $r;
953
        } else {
954
            $result["ERR"] = 1;
955
            $result["ERRINFO"] = "Passwords is mismatch";
956
        }
957
 
958
        return $result;
959
    }
960
 
504 alex-w 961
    /**
509 alex-w 962
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 963
     *
964
     * @author Alexander Wolf
965
     * @category Core
966
     *
967
     * @param string $name
968
     * @param string $actor
969
     * @param integer $versionID
970
     * @return string
971
     */
511 alex-w 972
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 973
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 974
        $sInfo = $this->secure->checkStr($info, 1);
975
        if ($sInfo == "") {
976
            $sInfo = "Версия дистрибутива";
977
        }
509 alex-w 978
        if ($sVersionID != 0) {
979
            // Режим редактирования
497 alex-w 980
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
981
            $rq =& $this->db->query($query);
982
            $rq->fetchInto($element);
509 alex-w 983
        }
984
 
511 alex-w 985
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 986
        if ($sVersionID != 0) {
987
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
988
        } else {
989
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
990
        }
509 alex-w 991
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
992
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
993
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
994
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 995
 
504 alex-w 996
        return $show;
509 alex-w 997
    }    
504 alex-w 998
 
520 alex-w 999
    /**
1000
     * Парсер схемы адреса репозитория
1001
     * FIXME Возможно не потребуется
1002
     *
1003
     * @author Alexander Wolf
1004
     * @category Core
1005
     *
1006
     * @param string $repstring
1007
     * @return integer
1008
     */
1009
    public function repositoryParser($repstring) {
1010
        $tokens = array();
1011
        $sections = array();
1012
        $tokens = split(" ",$repstring);
1013
 
1014
        if ($tokens[0] == "deb") {
1015
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
1016
            $url = parse_url($tokens[1]);
1017
            $distr  = $tokens[2];
1018
 
1019
            for($i=3;$i<count($tokens);$i++) {
1020
                $sections[] = $tokens[$i];
1021
            }
1022
        } else {
1023
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
1024
            if (stripos($tokens[1],"]")!=0) {
1025
                $sign = $tokens[1];
1026
                $url = parse_url($tokens[2]);
1027
                $base = $tokens[3];
1028
                $repname = $tokens[4];
1029
            } else {
1030
                $url = parse_url($tokens[1]);
1031
                $base = $tokens[2];
1032
                $repname = $tokens[3];
1033
            }
1034
        }
1035
 
1036
        $proto      = $url["scheme"]."://";
1037
        $addr       = $url["host"];
1038
        if ($url["port"]!="") {
1039
            $addr .= ":".$url["port"];
1040
        }
1041
        $path       = $url["path"];
1042
 
1043
        return 0;
1044
    }
1045
 
539 alex-w 1046
    /**
1047
     * Выгрузка картинок логотипов дистрибутивов
1048
     *
1049
     * @author Alexander Wolf
1050
     * @category Core
1051
     *
1052
     * @param string $path
1053
     * @param string $dist
1054
     * @param array $datafile
1055
     * @return integer
1056
     */
535 alex-w 1057
    public function uploadPicture($path, $dist, $datafile) {
1058
        $folder   = $path.$dist."-orig.png";
1059
        $folderN  = $path.$dist.".png";
1060
        $folderEM = $path.$dist."-em.png";
1061
 
1062
        $distlogo = 0;
1063
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
1064
            chmod($folder, 0644);
1065
            list($width, $height) = GetImageSize($folder);
1066
            $percent = 32/$height;
1067
            $newwidth = $width * $percent;
1068
            $newheight = $height * $percent;
1069
 
1070
            $output = ImageCreateTrueColor($newwidth, $newheight);
1071
            $source = ImageCreateFromPNG($folder);
1072
 
1073
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1074
            ImagePNG($output, $folderEM);
1075
 
1076
            $percent = 15/$height;
1077
            $newwidth = $width * $percent;
1078
            $newheight = $height * $percent;
1079
 
1080
            $output = ImageCreateTrueColor($newwidth, $newheight);
1081
 
1082
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1083
            ImagePNG($output, $folderN);
1084
 
1085
            unlink($folder);
1086
            $distlogo = 1;
1087
        }
1088
        return $distlogo;
1089
    }
547 alex-w 1090
 
1091
    /**
1092
     * Показ списка репозиториев
1093
     *
1094
     * @author Alexander Wolf
1095
     * @category Core
1096
     *
1097
     * @param string $name
1098
     * @param string $actor
1099
     * @param string $format
1100
     * @return string
1101
     */
548 alex-w 1102
    public function showRepositoriesList($name, $actor, $format = 'list') {
549 alex-w 1103
        $query  = "SELECT * FROM ".$this->prefix."repository r ";
548 alex-w 1104
        $query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
1105
        $rq =& $this->db->query($query);
1106
        $show = "<ul>";
1107
        while ($rq->fetchInto($element)) {
1108
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["rep_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["rep_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["repname"],1)." (".$this->secure->checkStr($element["rtype"],1).")</li>\n";
1109
        }
1110
        $show .= "</ul>";
547 alex-w 1111
        return $show;
1112
    }
1113
 
1114
    /**
1115
     * Форма создания/редактирвоания репозиториев
1116
     *
1117
     * @author Alexander Wolf
1118
     * @category Core
1119
     *
1120
     * @param integer $repID
1121
     * @param string $info
1122
     * @param string $reptype
1123
     * @return string
1124
     */
1125
    public function showRepositoriesForm($repID = 0, $info = "", $reptype = "") {
1126
        return $show;
1127
    }
304 alex-w 1128
}
1129
 
356 alex-w 1130
?>