Хранилища Subversion ant

Редакция

Редакция 595 | Редакция 598 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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();
582 alex-w 337
        $sDName = $this->secure->checkStr($distname);
321 alex-w 338
        $sDType = $this->secure->checkInt($disttype);
582 alex-w 339
        $sDUAgt = $this->secure->checkStr($distua);
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);
579 alex-w 370
        $sDName = $this->secure->checkStr($distname);
514 alex-w 371
        $sDType = $this->secure->checkInt($disttype);
579 alex-w 372
        $sDUAgt = $this->secure->checkStr($distua);
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);
582 alex-w 442
        $sDVersion  = $this->secure->checkStr($version);
443
        $sDVName    = $this->secure->checkStr($vname);
444
        $sDVCName   = $this->secure->checkStr($vcodename);
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
561 alex-w 603
     * @param string $format
522 alex-w 604
     * @return string
605
     */
560 alex-w 606
    public function showSectionsList($name, $actor, $format = 'html') {
607
        switch($format) {
608
            case 'html':
561 alex-w 609
                $query = "SELECT * FROM ".$this->prefix."section";
610
                $rq =& $this->db->query($query);
560 alex-w 611
                $show = "<ul>\n";
612
                while ($rq->fetchInto($element)) {
613
                    $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";
614
                }
615
                $show .= "</ul>";
616
                break;
617
            case 'innerhtml':
618
                $show = "";
561 alex-w 619
                $repID = $this->secure->checkInt($actor);
620
                if ($repID==0) {
621
                    $query = "SELECT * FROM ".$this->prefix."section";
622
                    $rq =& $this->db->query($query);
623
                    while ($rq->fetchInto($element)) {
567 alex-w 624
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 625
                    }
626
                } else {
627
                    $query = "SELECT * FROM ".$this->prefix."section s JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$repID'";
628
                    $rq =& $this->db->query($query);
629
                    while ($rq->fetchInto($element)) {
567 alex-w 630
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."' checked>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 631
                    }
632
                    $query = "SELECT s.* FROM ".$this->prefix."section s WHERE s.sect_id NOT IN (SELECT sect_id FROM ".$this->prefix."sect2rep WHERE rep_id='$repID')";
563 alex-w 633
                    $rq =& $this->db->query($query);
561 alex-w 634
                    while ($rq->fetchInto($element)) {
567 alex-w 635
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 636
                    }
637
                }
638
 
560 alex-w 639
                break;
522 alex-w 640
        }
641
 
642
        return $show;
643
    }
644
 
523 alex-w 645
    /**
646
     * Вывод формы редактирования/добавления секций
647
     *
648
     * @author Alexander Wolf
649
     * @category Core
650
     *
651
     * @param integer $sectionID
652
     * @param string $info
653
     * @return string
654
     */
655
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 656
        $sSectID = $this->secure->checkInt($sectionID);
657
        $sInfo = $this->secure->checkStr($info, 1);
658
        if ($sInfo == "") {
659
            $sInfo = "Секция";
660
        }
661
        if ($sSectID != 0) {
662
            // Режим редактирования
663
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
664
            $rq =& $this->db->query($query);
665
            $rq->fetchInto($element);
666
        }
667
 
668
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
669
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
670
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
671
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
672
 
673
        return $show;
674
    }
675
 
676
    /**
523 alex-w 677
     * Обновление информации о секции
678
     *
679
     * @author Alexander Wolf
680
     * @category Core
681
     *
682
     * @param integer $sectionID
683
     * @param string $sname
684
     * @param string $sinfo
685
     * @return array
686
     */
687
    public function updateSection($sectionID, $sname, $sinfo = "") {
688
        $result = array();
689
        $sSectID    = $this->secure->checkInt($sectionID);
579 alex-w 690
        $sSName     = $this->secure->checkStr($sname);
691
        $sSInfo     = $this->secure->checkStr($sinfo);
523 alex-w 692
 
693
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
694
        $rq =& $this->db->query($query);
695
        if (PEAR::isError($this->db)) {
696
            $result["ERR"] = 1;
697
            $result["ERRINFO"] = $this->db->getMessage();
698
        } else {
699
            $result["ERR"] = 0;
700
        }
701
 
702
        return $result;
703
    }
704
 
705
    /**
706
     * Удаление информации о секции
707
     *
708
     * @author Alexander Wolf
709
     * @category Core
710
     *
711
     * @param integer $sectionID
712
     * @return array
713
     */
714
    public function dropSection($sectionID) {
715
        $result = array();
716
        $sSectID    = $this->secure->checkInt($sectionID);
717
 
718
        // Удаление секции
719
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
720
        $rq =& $this->db->query($query);
721
        if (PEAR::isError($this->db)) {
722
            $result["ERR"] = 1;
723
            $result["ERRINFO"] = $this->db->getMessage();
724
        } else {
725
            $result["ERR"] = 0;
726
        }
727
 
728
        return $result;
729
    }
730
 
731
    /**
732
     * Добавление новой секции
733
     *
734
     * @author Alexander Wolf
735
     * @category Core
736
     *
737
     * @param string $sname
738
     * @param string $sinfo
739
     * @return array
740
     */
741
    public function addSection($sname, $sinfo = "") {
742
        $result = array();
582 alex-w 743
        $sSName = $this->secure->checkStr($sname);
744
        $sSInfo = $this->secure->checkStr($sinfo);
523 alex-w 745
 
746
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
747
        $rq =& $this->db->query($query);
748
        if (PEAR::isError($this->db)) {
749
            $result["ERR"] = 1;
750
            $result["ERRINFO"] = $this->db->getMessage();
751
        } else {
752
            $result["ERR"] = 0;
753
        }
754
 
755
        return $result;
756
    }
757
 
758
    /**
568 alex-w 759
     * Вывод списка поддерживаемых архитектур
760
     *
761
     * @author Alexander Wolf
762
     * @category Core
763
     *
764
     * @param string $name
765
     * @param string $actor
766
     * @param string $format
767
     * @return string
768
     */
769
    public function showArchList($name, $actor, $format = 'list') {
770
        switch($format) {
771
            case 'list':
772
                $query = "SELECT * FROM ".$this->prefix."arch";
773
                $rq =& $this->db->query($query);
774
                $show = "<ul>\n";
775
                while ($rq->fetchInto($element)) {
776
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["arch_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["arch_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["arch"],1)."</li>\n";
777
                }
778
                $show .= "</ul>";
779
                break;
780
            case 'innerhtml':
781
                $show = "";
782
                $repID = $this->secure->checkInt($actor);
783
                if ($archID==0) {
784
                    $query = "SELECT * FROM ".$this->prefix."arch";
785
                    $rq =& $this->db->query($query);
786
                    while ($rq->fetchInto($element)) {
787
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
788
                    }
789
                } else {
790
                    $query = "SELECT * FROM ".$this->prefix."arch a JOIN ".$this->prefix."arch2rep r ON a.arch_id=r.arch_id WHERE r.rep_id='$repID'";
791
                    $rq =& $this->db->query($query);
792
                    while ($rq->fetchInto($element)) {
793
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."' checked>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
794
                    }
795
                    $query = "SELECT a.* FROM ".$this->prefix."arch a WHERE a.arch_id NOT IN (SELECT arch_id FROM ".$this->prefix."arch2rep WHERE rep_id='$repID')";
796
                    $rq =& $this->db->query($query);
797
                    while ($rq->fetchInto($element)) {
798
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
799
                    }
800
                }
801
                break;
802
        }
803
        return $show;
804
    }
805
 
806
    /**
807
     * Добавление новой архитектуры
808
     *
809
     * @author Alexander Wolf
810
     * @category Core
811
     *
812
     * @param string $arch
813
     * @return array
814
     */
815
    public function addArch($arch) {
816
        $result = array();
582 alex-w 817
        $sArch = $this->secure->checkStr($arch);
568 alex-w 818
 
819
        $query = "INSERT INTO ".$this->prefix."arch SET arch='".$sArch."'";
820
        $rq =& $this->db->query($query);
821
        if (PEAR::isError($this->db)) {
822
            $result["ERR"] = 1;
823
            $result["ERRINFO"] = $this->db->getMessage();
824
        } else {
825
            $result["ERR"] = 0;
826
        }
827
 
828
        return $result;
829
    }
830
 
831
    /**
832
     * Удаление информации об архитектуре
833
     *
834
     * @author Alexander Wolf
835
     * @category Core
836
     *
837
     * @param integer $archID
838
     * @return array
839
     */
840
    public function dropArch($archID) {
841
        $result = array();
842
        $sArchID    = $this->secure->checkInt($archID);
843
 
844
        // Удаление архитектуры
845
        $query = "DELETE FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
846
        $rq =& $this->db->query($query);
847
        if (PEAR::isError($this->db)) {
848
            $result["ERR"] = 1;
849
            $result["ERRINFO"] = $this->db->getMessage();
850
        } else {
851
            $result["ERR"] = 0;
852
        }
853
 
854
        // Удаление архитектуры из списка репозиториев
855
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE arch_id='".$sArchID."'";
856
        $rq =& $this->db->query($query);
857
        if (PEAR::isError($this->db)) {
858
            $result["ERR"] = 1;
859
            $result["ERRINFO"] = $this->db->getMessage();
860
        } else {
861
            $result["ERR"] = 0;
862
        }
863
        return $result;
864
    }
865
 
866
    /**
867
     * Обновление информации об архитектуре
868
     *
869
     * @author Alexander Wolf
870
     * @category Core
871
     *
872
     * @param integer $archID
873
     * @param string $arch
874
     * @return array
875
     */
876
    public function updateArch($archID, $arch) {
877
        $result = array();
878
        $sArchID    = $this->secure->checkInt($archID);
579 alex-w 879
        $sArch      = $this->secure->checkStr($arch);
568 alex-w 880
 
881
        $query = "UPDATE ".$this->prefix."arch SET arch='".$sArch."' WHERE arch_id='".$sArchID."'";
882
        $rq =& $this->db->query($query);
883
        if (PEAR::isError($this->db)) {
884
            $result["ERR"] = 1;
885
            $result["ERRINFO"] = $this->db->getMessage();
886
        } else {
887
            $result["ERR"] = 0;
888
        }
889
 
890
        return $result;
891
    }
892
 
893
    /**
894
     * Вывод формы редактирования/добавления архитектур
895
     *
896
     * @author Alexander Wolf
897
     * @category Core
898
     *
899
     * @param integer $archID
900
     * @param string $info
901
     * @return string
902
     */
903
    public function showArchForm($archID = 0, $info = "") {
904
        $sArchID = $this->secure->checkInt($archID);
905
        $sInfo = $this->secure->checkStr($info, 1);
906
        if ($sInfo == "") {
907
            $sInfo = "Архитектура";
908
        }
909
        if ($sArchID != 0) {
910
            // Режим редактирования
911
            $query = "SELECT * FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
912
            $rq =& $this->db->query($query);
913
            $rq->fetchInto($element);
914
        }
915
 
916
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
917
        $show .= "<div class='inputbox'><label for='arch'>Архитектура:</label> <input type='text' name='arch' id='arch' value='".$this->secure->checkStr($element["arch"],1)."'></div>\n";
918
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
919
 
920
        return $show;
921
    }
922
 
923
    /**
570 alex-w 924
     * Вывод списка схем репозиториев
925
     *
926
     * @author Alexander Wolf
927
     * @category Core
928
     *
929
     * @param string $name
930
     * @param string $actor
931
     * @param string $format
932
     * @return string
933
     */
934
    public function showSchemeList($name, $actor, $format = 'list') {
935
        switch($format) {
936
            case 'list':
937
                $query = "SELECT * FROM ".$this->prefix."repscheme";
938
                $rq =& $this->db->query($query);
939
                $show = "<ul>\n";
940
                while ($rq->fetchInto($element)) {
941
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["scheme_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["scheme_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["scheme"],1)."</li>\n";
942
                }
943
                $show .= "</ul>";
944
                break;
945
            case 'innerhtml':
946
                $repID = $this->secure->checkInt($actor);
947
                $query = "SELECT * FROM ".$this->prefix."repscheme";
948
                $rq =& $this->db->query($query);
949
                $show = "<select name='".$name."' id='".$name."'>\n";
950
                while ($rq->fetchInto($element)) {
951
                    if ($element["scheme_id"]==$repID) {
952
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."' selected>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
953
                    } else {
954
                    $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."'>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
955
                    }
956
                }
957
                $show .= "</select>";
958
                break;
959
        }
960
        return $show;
961
    }
962
 
963
    /**
964
     * Добавление новой схемы репозитория
965
     *
966
     * @author Alexander Wolf
967
     * @category Core
968
     *
969
     * @param string $scheme
970
     * @return array
971
     */
972
    public function addScheme($scheme) {
973
        $result = array();
582 alex-w 974
        $sScheme = $this->secure->checkStr($scheme);
570 alex-w 975
 
976
        $query = "INSERT INTO ".$this->prefix."repscheme SET scheme='".$sScheme."'";
977
        $rq =& $this->db->query($query);
978
        if (PEAR::isError($this->db)) {
979
            $result["ERR"] = 1;
980
            $result["ERRINFO"] = $this->db->getMessage();
981
        } else {
982
            $result["ERR"] = 0;
983
        }
984
 
985
        return $result;
986
    }
987
 
988
    /**
989
     * Удаление информации о схеме репозитория
990
     *
991
     * @author Alexander Wolf
992
     * @category Core
993
     *
994
     * @param integer $schemeID
995
     * @return array
996
     */
997
    public function dropScheme($schemeID) {
998
        $result = array();
999
        $sSchemeID    = $this->secure->checkInt($schemeID);
1000
 
1001
        // Удаление схемы
1002
        $query = "DELETE FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1003
        $rq =& $this->db->query($query);
1004
        if (PEAR::isError($this->db)) {
1005
            $result["ERR"] = 1;
1006
            $result["ERRINFO"] = $this->db->getMessage();
1007
        } else {
1008
            $result["ERR"] = 0;
1009
        }
1010
 
1011
        return $result;
1012
    }
1013
 
1014
    /**
1015
     * Обновление информации о схеме репозитория
1016
     *
1017
     * @author Alexander Wolf
1018
     * @category Core
1019
     *
1020
     * @param integer $schemeID
1021
     * @param string $info
1022
     * @return array
1023
     */
1024
    public function updateScheme($schemeID, $info) {
1025
        $result = array();
1026
        $sSchemeID    = $this->secure->checkInt($schemeID);
579 alex-w 1027
        $sScheme      = $this->secure->checkStr($info);
570 alex-w 1028
 
1029
        $query = "UPDATE ".$this->prefix."repscheme SET scheme='".$sScheme."' WHERE scheme_id='".$sSchemeID."'";
1030
        $rq =& $this->db->query($query);
1031
        if (PEAR::isError($this->db)) {
1032
            $result["ERR"] = 1;
1033
            $result["ERRINFO"] = $this->db->getMessage();
1034
        } else {
1035
            $result["ERR"] = 0;
1036
        }
1037
 
1038
        return $result;
1039
    }
1040
 
1041
    /**
1042
     * Вывод формы редактирования/добавления схем репозиториев
1043
     *
1044
     * @author Alexander Wolf
1045
     * @category Core
1046
     *
1047
     * @param integer $schemeID
1048
     * @param string $info
1049
     * @return string
1050
     */
1051
    public function showSchemeForm($schemeID = 0, $info = "") {
1052
        $sSchemeID = $this->secure->checkInt($schemeID);
1053
        $sInfo = $this->secure->checkStr($info, 1);
1054
        if ($sInfo == "") {
1055
            $sInfo = "Схема репозитория";
1056
        }
571 alex-w 1057
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
570 alex-w 1058
        if ($sSchemeID != 0) {
1059
            // Режим редактирования
1060
            $query = "SELECT * FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1061
            $rq =& $this->db->query($query);
573 alex-w 1062
            $rq->fetchInto($element);            
1063
        }
571 alex-w 1064
 
573 alex-w 1065
        $show .= "<div class='inputbox'><label for='scheme'>Схема репозитория:</label> <input type='text' name='scheme' id='scheme' value='".$this->secure->checkStr($element["scheme"],1)."'></div>\n";
570 alex-w 1066
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1067
 
1068
        return $show;
1069
    }
1070
 
1071
    /**
574 alex-w 1072
     * Вывод списка протоколов
1073
     *
1074
     * @author Alexander Wolf
1075
     * @category Core
1076
     *
1077
     * @param string $name
1078
     * @param string $actor
1079
     * @param string $format
1080
     * @return string
1081
     */
1082
    public function showProtoList($name, $actor, $format = 'list') {
1083
        switch($format) {
1084
            case 'list':
1085
                $query = "SELECT * FROM ".$this->prefix."protos";
1086
                $rq =& $this->db->query($query);
1087
                $show = "<ul>\n";
1088
                while ($rq->fetchInto($element)) {
1089
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["proto_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["proto_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["proto"],1)."</li>\n";
1090
                }
1091
                $show .= "</ul>";
1092
                break;
1093
            case 'innerhtml':
1094
                $protoID = $this->secure->checkInt($actor);
1095
                $query = "SELECT * FROM ".$this->prefix."protos";
1096
                $rq =& $this->db->query($query);
1097
                $show = "<select name='".$name."' id='".$name."'>\n";
1098
                while ($rq->fetchInto($element)) {
1099
                    if ($element["proto_id"]==$protoID) {
1100
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."' selected>".$this->secure->checkStr($element["proto"],1)."</option>\n";
1101
                    } else {
580 alex-w 1102
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."'>".$this->secure->checkStr($element["proto"],1)."</option>\n";
574 alex-w 1103
                    }
1104
                }
1105
                $show .= "</select>";
1106
                break;
1107
        }
1108
        return $show;
1109
    }
1110
 
1111
    /**
1112
     * Добавление нового протокола
1113
     *
1114
     * @author Alexander Wolf
1115
     * @category Core
1116
     *
1117
     * @param string $proto
1118
     * @return array
1119
     */
1120
    public function addProto($proto) {
1121
        $result = array();
582 alex-w 1122
        $sProto = $this->secure->checkStr($proto);
574 alex-w 1123
 
1124
        $query = "INSERT INTO ".$this->prefix."protos SET proto='".$sProto."'";
1125
        $rq =& $this->db->query($query);
1126
        if (PEAR::isError($this->db)) {
1127
            $result["ERR"] = 1;
1128
            $result["ERRINFO"] = $this->db->getMessage();
1129
        } else {
1130
            $result["ERR"] = 0;
1131
        }
1132
 
1133
        return $result;
1134
    }
1135
 
1136
    /**
1137
     * Удаление информации о протоколе
1138
     *
1139
     * @author Alexander Wolf
1140
     * @category Core
1141
     *
1142
     * @param integer $protoID
1143
     * @return array
1144
     */
1145
    public function dropProto($protoID) {
1146
        $result = array();
1147
        $sProtoID    = $this->secure->checkInt($protoID);
1148
 
1149
        // Удаление протокола
1150
        $query = "DELETE FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1151
        $rq =& $this->db->query($query);
1152
        if (PEAR::isError($this->db)) {
1153
            $result["ERR"] = 1;
1154
            $result["ERRINFO"] = $this->db->getMessage();
1155
        } else {
1156
            $result["ERR"] = 0;
1157
        }
1158
 
1159
        return $result;
1160
    }
1161
 
1162
    /**
1163
     * Обновление информации о протоколе
1164
     *
1165
     * @author Alexander Wolf
1166
     * @category Core
1167
     *
1168
     * @param integer $protoID
1169
     * @param string $info
1170
     * @return array
1171
     */
1172
    public function updateProto($protoID, $info) {
1173
        $result = array();
1174
        $sProtoID    = $this->secure->checkInt($protoID);
579 alex-w 1175
        $sProto      = $this->secure->checkStr($info);
574 alex-w 1176
 
1177
        $query = "UPDATE ".$this->prefix."protos SET proto='".$sProto."' WHERE proto_id='".$sProtoID."'";
1178
        $rq =& $this->db->query($query);
1179
        if (PEAR::isError($this->db)) {
1180
            $result["ERR"] = 1;
1181
            $result["ERRINFO"] = $this->db->getMessage();
1182
        } else {
1183
            $result["ERR"] = 0;
1184
        }
1185
 
1186
        return $result;
1187
    }
1188
 
1189
    /**
1190
     * Вывод формы редактирования/добавления протоколов
1191
     *
1192
     * @author Alexander Wolf
1193
     * @category Core
1194
     *
1195
     * @param integer $protoID
1196
     * @param string $info
1197
     * @return string
1198
     */
1199
    public function showProtoForm($protoID = 0, $info = "") {
1200
        $sProtoID = $this->secure->checkInt($protoID);
1201
        $sInfo = $this->secure->checkStr($info, 1);
1202
        if ($sInfo == "") {
1203
            $sInfo = "Протокол доступа";
1204
        }
1205
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1206
        if ($sProtoID != 0) {
1207
            // Режим редактирования
1208
            $query = "SELECT * FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1209
            $rq =& $this->db->query($query);
1210
            $rq->fetchInto($element);
1211
        }
1212
 
1213
        $show .= "<div class='inputbox'><label for='proto'>Протокол доступа:</label> <input type='text' name='proto' id='proto' value='".$this->secure->checkStr($element["proto"],1)."'></div>\n";
1214
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1215
 
1216
        return $show;
1217
    }
1218
 
1219
    /**
582 alex-w 1220
     * Вывод списка хостов
1221
     *
1222
     * @author Alexander Wolf
1223
     * @category Core
1224
     *
1225
     * @param string $name
1226
     * @param string $actor
1227
     * @param string $format
1228
     * @return string
1229
     */
1230
    public function showHostsList($name, $actor, $format = 'list') {
1231
        switch($format) {
1232
            case 'list':
1233
                $query = "SELECT * FROM ".$this->prefix."rephost";
1234
                $rq =& $this->db->query($query);
1235
                $show = "<ul>\n";
1236
                while ($rq->fetchInto($element)) {
1237
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rhost_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rhost_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rhost"],1)."</li>\n";
1238
                }
1239
                $show .= "</ul>";
1240
                break;
1241
            case 'innerhtml':
1242
                $hostID = $this->secure->checkInt($actor);
1243
                $query = "SELECT * FROM ".$this->prefix."rephost";
1244
                $rq =& $this->db->query($query);
1245
                $show = "<select name='".$name."' id='".$name."'>\n";
1246
                while ($rq->fetchInto($element)) {
1247
                    if ($element["rhost_id"]==$hostID) {
1248
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."' selected>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1249
                    } else {
1250
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."'>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1251
                    }
1252
                }
1253
                $show .= "</select>";
1254
                break;
1255
        }
1256
        return $show;
1257
    }
1258
 
1259
    /**
1260
     * Добавление нового хоста
1261
     *
1262
     * @author Alexander Wolf
1263
     * @category Core
1264
     *
1265
     * @param string $host
1266
     * @return array
1267
     */
1268
    public function addHost($host) {
1269
        $result = array();
1270
        $sHost = $this->secure->checkStr($host);
1271
 
586 alex-w 1272
        $query = "INSERT INTO ".$this->prefix."rephost SET rhost='".$sHost."'";
582 alex-w 1273
        $rq =& $this->db->query($query);
1274
        if (PEAR::isError($this->db)) {
1275
            $result["ERR"] = 1;
1276
            $result["ERRINFO"] = $this->db->getMessage();
1277
        } else {
1278
            $result["ERR"] = 0;
1279
        }
1280
 
1281
        return $result;
1282
    }
1283
 
1284
    /**
1285
     * Удаление информации о хосте
1286
     *
1287
     * @author Alexander Wolf
1288
     * @category Core
1289
     *
1290
     * @param integer $hostID
1291
     * @return array
1292
     */
1293
    public function dropHost($hostID) {
1294
        $result = array();
1295
        $sHostID    = $this->secure->checkInt($hostID);
1296
 
1297
        // Удаление хоста
1298
        $query = "DELETE FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1299
        $rq =& $this->db->query($query);
1300
        if (PEAR::isError($this->db)) {
1301
            $result["ERR"] = 1;
1302
            $result["ERRINFO"] = $this->db->getMessage();
1303
        } else {
1304
            $result["ERR"] = 0;
1305
        }
1306
 
1307
        return $result;
1308
    }
1309
 
1310
    /**
1311
     * Обновление информации о хосте
1312
     *
1313
     * @author Alexander Wolf
1314
     * @category Core
1315
     *
1316
     * @param integer $hostID
1317
     * @param string $info
1318
     * @return array
1319
     */
1320
    public function updateHost($hostID, $info) {
1321
        $result = array();
1322
        $sHostID    = $this->secure->checkInt($hostID);
1323
        $sHost      = $this->secure->checkStr($info);
1324
 
1325
        $query = "UPDATE ".$this->prefix."rephost SET rhost='".$sHost."' WHERE rhost_id='".$sHostID."'";
1326
        $rq =& $this->db->query($query);
1327
        if (PEAR::isError($this->db)) {
1328
            $result["ERR"] = 1;
1329
            $result["ERRINFO"] = $this->db->getMessage();
1330
        } else {
1331
            $result["ERR"] = 0;
1332
        }
1333
 
1334
        return $result;
1335
    }
1336
 
1337
    /**
1338
     * Вывод формы редактирования/добавления хостов
1339
     *
1340
     * @author Alexander Wolf
1341
     * @category Core
1342
     *
1343
     * @param integer $hostID
1344
     * @param string $info
1345
     * @return string
1346
     */
1347
    public function showHostForm($hostID = 0, $info = "") {
1348
        $sHostID = $this->secure->checkInt($hostID);
1349
        $sInfo = $this->secure->checkStr($info, 1);
1350
        if ($sInfo == "") {
1351
            $sInfo = "Хост репозитория";
1352
        }
1353
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1354
        if ($sHostID != 0) {
1355
            // Режим редактирования
1356
            $query = "SELECT * FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1357
            $rq =& $this->db->query($query);
1358
            $rq->fetchInto($element);
1359
        }
1360
 
1361
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> <input type='text' name='rhost' id='rhost' value='".$this->secure->checkStr($element["rhost"],1)."'></div>\n";
1362
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1363
 
1364
        return $show;
1365
    }
1366
 
1367
    /**
589 alex-w 1368
     * Вывод списка корневых папок
1369
     *
1370
     * @author Alexander Wolf
1371
     * @category Core
1372
     *
1373
     * @param string $name
1374
     * @param string $actor
1375
     * @param string $format
1376
     * @return string
1377
     */
1378
    public function showFoldersList($name, $actor, $format = 'list') {
1379
        switch($format) {
1380
            case 'list':
1381
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1382
                $rq =& $this->db->query($query);
1383
                $show = "<ul>\n";
1384
                while ($rq->fetchInto($element)) {
1385
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rfolder_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rfolder_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rfolder"],1)."</li>\n";
1386
                }
1387
                $show .= "</ul>";
1388
                break;
1389
            case 'innerhtml':
1390
                $folderID = $this->secure->checkInt($actor);
1391
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1392
                $rq =& $this->db->query($query);
1393
                $show = "<select name='".$name."' id='".$name."'>\n";
1394
                while ($rq->fetchInto($element)) {
1395
                    if ($element["rfolder_id"]==$folderID) {
1396
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."' selected>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1397
                    } else {
1398
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."'>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1399
                    }
1400
                }
1401
                $show .= "</select>";
1402
                break;
1403
        }
1404
        return $show;
1405
    }
1406
 
1407
    /**
1408
     * Добавление нового корневого каталога
1409
     *
1410
     * @author Alexander Wolf
1411
     * @category Core
1412
     *
1413
     * @param string $flder
1414
     * @return array
1415
     */
1416
    public function addFolder($folder) {
1417
        $result = array();
1418
        $sFolder = $this->secure->checkStr($folder);
1419
 
1420
        $query = "INSERT INTO ".$this->prefix."repfolder SET rfolder='".$sFolder."'";
1421
        $rq =& $this->db->query($query);
1422
        if (PEAR::isError($this->db)) {
1423
            $result["ERR"] = 1;
1424
            $result["ERRINFO"] = $this->db->getMessage();
1425
        } else {
1426
            $result["ERR"] = 0;
1427
        }
1428
 
1429
        return $result;
1430
    }
1431
 
1432
    /**
1433
     * Удаление информации о корневой папке
1434
     *
1435
     * @author Alexander Wolf
1436
     * @category Core
1437
     *
1438
     * @param integer $folderID
1439
     * @return array
1440
     */
1441
    public function dropFolder($folderID) {
1442
        $result = array();
1443
        $sFolderID    = $this->secure->checkInt($folderID);
1444
 
1445
        // Удаление корневой папки
1446
        $query = "DELETE FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1447
        $rq =& $this->db->query($query);
1448
        if (PEAR::isError($this->db)) {
1449
            $result["ERR"] = 1;
1450
            $result["ERRINFO"] = $this->db->getMessage();
1451
        } else {
1452
            $result["ERR"] = 0;
1453
        }
1454
 
1455
        return $result;
1456
    }
1457
 
1458
    /**
1459
     * Обновление информации о корневой папки
1460
     *
1461
     * @author Alexander Wolf
1462
     * @category Core
1463
     *
1464
     * @param integer $folderID
1465
     * @param string $info
1466
     * @return array
1467
     */
1468
    public function updateFolder($folderID, $info) {
1469
        $result = array();
1470
        $sFolderID    = $this->secure->checkInt($folderID);
1471
        $sFolder      = $this->secure->checkStr($info);
1472
 
1473
        $query = "UPDATE ".$this->prefix."repfolder SET rfolder='".$sFolder."' WHERE rfolder_id='".$sFolderID."'";
1474
        $rq =& $this->db->query($query);
1475
        if (PEAR::isError($this->db)) {
1476
            $result["ERR"] = 1;
1477
            $result["ERRINFO"] = $this->db->getMessage();
1478
        } else {
1479
            $result["ERR"] = 0;
1480
        }
1481
 
1482
        return $result;
1483
    }
1484
 
1485
    /**
1486
     * Вывод формы редактирования/добавления корневых папок
1487
     *
1488
     * @author Alexander Wolf
1489
     * @category Core
1490
     *
1491
     * @param integer $folderID
1492
     * @param string $info
1493
     * @return string
1494
     */
1495
    public function showFolderForm($folderID = 0, $info = "") {
1496
        $sFolderID = $this->secure->checkInt($folderID);
1497
        $sInfo = $this->secure->checkStr($info, 1);
1498
        if ($sInfo == "") {
1499
            $sInfo = "Корневая папка";
1500
        }
1501
        if ($sFolderID != 0) {
1502
            // Режим редактирования
1503
            $query = "SELECT * FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1504
            $rq =& $this->db->query($query);
1505
            $rq->fetchInto($element);
1506
        }
1507
 
1508
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1509
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> <input type='text' name='rfolder' id='rfolder' value='".$this->secure->checkStr($element["rfolder"],1)."'></div>\n";
1510
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1511
 
1512
        return $show;
1513
    }
1514
 
1515
    /**
539 alex-w 1516
     * Показывает список подписей
1517
     *
1518
     * @author Alexander Wolf
1519
     * @category Core
1520
     *
1521
     * @param string $name
1522
     * @param string $actor
596 alex-w 1523
     * @param string $format
539 alex-w 1524
     * @return string
1525
     */
594 alex-w 1526
    public function showSignsList($name, $actor, $format = 'list') {
539 alex-w 1527
        $query = "SELECT * FROM ".$this->prefix."signs";
1528
        $rq =& $this->db->query($query);
594 alex-w 1529
        switch ($format) {
1530
            case 'list':
1531
                $show = "<ul>\n";
1532
                while ($rq->fetchInto($element)) {
1533
                    $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";
1534
                }
1535
                $show .= "</ul>";
1536
                break;
1537
            case 'innerhtml':
1538
                $signID = $this->secure->checkInt($actor);
1539
                $show  = "<select name='".$name."' id='".$name."'>\n";
1540
                $show .= "<option value='0'>Подписи нет</option>\n";
1541
                while ($rq->fetchInto($element)) {
1542
                    if ($element["sign_id"]==$signID) {
1543
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."' selected>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1544
                    } else {
1545
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."'>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1546
                    }
1547
                }
1548
                $show .= "</select>\n";
1549
                break;
539 alex-w 1550
        }
1551
 
1552
        return $show;
1553
    }
1554
 
1555
    /**
1556
     * Вывод формы редактирования/добавления подписей
1557
     *
1558
     * @author Alexander Wolf
1559
     * @category Core
1560
     *
1561
     * @param integer $sectionID
1562
     * @param string $info
1563
     * @return string
1564
     */
1565
    public function showSignsForm($signID = 0, $info = "") {
1566
        $sSignID = $this->secure->checkInt($signID);
1567
        $sInfo = $this->secure->checkStr($info, 1);
1568
        if ($sInfo == "") {
1569
            $sInfo = "Подписи";
1570
        }
1571
        if ($sSignID != 0) {
1572
            // Режим редактирования
1573
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1574
            $rq =& $this->db->query($query);
1575
            $rq->fetchInto($element);
1576
        }
1577
 
1578
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1579
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
1580
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
1581
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1582
 
1583
        return $show;
1584
    }
1585
 
1586
    /**
1587
     * Обновление информации о секции
1588
     *
1589
     * @author Alexander Wolf
1590
     * @category Core
1591
     *
1592
     * @param integer $sectionID
1593
     * @param string $sname
1594
     * @param string $sinfo
1595
     * @return array
1596
     */
1597
    public function updateSign($signID, $sname, $sinfo = "") {
1598
        $result = array();
1599
        $sSignID    = $this->secure->checkInt($signID);
579 alex-w 1600
        $sSName     = $this->secure->checkStr($sname);
1601
        $sSInfo     = $this->secure->checkStr($sinfo);
539 alex-w 1602
 
1603
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
1604
        $rq =& $this->db->query($query);
1605
        if (PEAR::isError($this->db)) {
1606
            $result["ERR"] = 1;
1607
            $result["ERRINFO"] = $this->db->getMessage();
1608
        } else {
1609
            $result["ERR"] = 0;
1610
        }
1611
 
1612
        return $result;
1613
    }
1614
 
1615
    /**
1616
     * Удаление информации о подписи
1617
     *
1618
     * @author Alexander Wolf
1619
     * @category Core
1620
     *
1621
     * @param integer $sectionID
1622
     * @return array
1623
     */
540 alex-w 1624
    public function dropSign($signID) {
539 alex-w 1625
        $result = array();
1626
        $sSignID    = $this->secure->checkInt($signID);
1627
 
1628
        // Удаление подписи
1629
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1630
        $rq =& $this->db->query($query);
1631
        if (PEAR::isError($this->db)) {
1632
            $result["ERR"] = 1;
1633
            $result["ERRINFO"] = $this->db->getMessage();
1634
        } else {
1635
            $result["ERR"] = 0;
1636
        }
1637
 
1638
        return $result;
1639
    }
1640
 
1641
    /**
540 alex-w 1642
     * Добавление новой подписи
539 alex-w 1643
     *
1644
     * @author Alexander Wolf
1645
     * @category Core
1646
     *
1647
     * @param string $sname
1648
     * @param string $sinfo
1649
     * @return array
1650
     */
540 alex-w 1651
    public function addSign($sname, $sinfo = "") {
539 alex-w 1652
        $result = array();
582 alex-w 1653
        $sSName = $this->secure->checkStr($sname);
1654
        $sSInfo = $this->secure->checkStr($sinfo);
539 alex-w 1655
 
540 alex-w 1656
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 1657
        $rq =& $this->db->query($query);
1658
        if (PEAR::isError($this->db)) {
1659
            $result["ERR"] = 1;
1660
            $result["ERRINFO"] = $this->db->getMessage();
1661
        } else {
1662
            $result["ERR"] = 0;
1663
        }
1664
 
1665
        return $result;
1666
    }
540 alex-w 1667
 
539 alex-w 1668
    /**
463 alex-w 1669
     * Проверка пароля (из формы авторизации)
1670
     *
1671
     * @author Alexander Wolf
1672
     * @category Core
1673
     *
1674
     * @param string $word
1675
     * @return array
1676
     */
368 alex-w 1677
    public function checkSign($word) {
359 alex-w 1678
        $result = array();
1679
 
1680
        $sHash = $this->secure->encryptStr($word);
1681
        $pwd   = $this->getOption("passwd");
1682
        if ($sHash == $pwd["OptValue"]) {
1683
            $result["ERR"] = 0;
1684
            $result["Location"] = "manager.php";
1685
            setcookie($this->cookie, $sHash);
1686
        } else {
1687
            $result["ERR"] = 1;
1688
            $result["ERRINFO"] = "Password not valid";
368 alex-w 1689
            $result["Location"] = "manager.php?error=1";
359 alex-w 1690
        }
1691
 
1692
        return $result;
358 alex-w 1693
    }
357 alex-w 1694
 
463 alex-w 1695
    /**
1696
     * Проверка пароля (из cookies)
1697
     *
1698
     * @author Alexander Wolf
1699
     * @category Core
1700
     *
1701
     * @param string $hash
1702
     * @return array
1703
     */
368 alex-w 1704
    public function checkCookieSign($hash) {
359 alex-w 1705
        $result = array();
1706
 
1707
        $pwd = $this->getOption("passwd");
1708
        if ($hash == $pwd["OptValue"]) {
1709
            $result["ERR"] = 0;
1710
        } else {
1711
            $result["ERR"] = 1;
1712
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 1713
            $result["Location"] = "manager.php";
359 alex-w 1714
        }
1715
 
1716
        return $result;
1717
    }
1718
 
463 alex-w 1719
    /**
1720
     * Форма ввода пароля
1721
     *
1722
     * @author Alexander Wolf
1723
     * @category Core
1724
     *
1725
     * @return string
1726
     */
368 alex-w 1727
    public function showSigninForm() {
425 alex-w 1728
        $show  = "<div id='regform'>";
1729
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 1730
        $show .= "<fieldset><legend>Пароль</legend>\n";
1731
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 1732
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 1733
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 1734
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 1735
 
1736
        return $show;
1737
    }
1738
 
463 alex-w 1739
    /**
1740
     * Обновление пароля
1741
     *
1742
     * @author Alexander Wolf
1743
     * @category Core
1744
     *
1745
     * @param string $word1
1746
     * @param string $word2
1747
     * @return array
1748
     */
368 alex-w 1749
    public function updatePassword($word1, $word2) {
359 alex-w 1750
        $result = array();
1751
 
1752
        if ($word1 == $word2) {
1753
            $sWord = $this->secure->encryptStr($word1);
1754
            $r = $this->setOption("passwd", $sWord);
1755
            $result = $r;
1756
        } else {
1757
            $result["ERR"] = 1;
1758
            $result["ERRINFO"] = "Passwords is mismatch";
1759
        }
1760
 
1761
        return $result;
1762
    }
1763
 
504 alex-w 1764
    /**
509 alex-w 1765
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 1766
     *
1767
     * @author Alexander Wolf
1768
     * @category Core
1769
     *
1770
     * @param string $name
1771
     * @param string $actor
1772
     * @param integer $versionID
1773
     * @return string
1774
     */
511 alex-w 1775
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 1776
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 1777
        $sInfo = $this->secure->checkStr($info, 1);
1778
        if ($sInfo == "") {
1779
            $sInfo = "Версия дистрибутива";
1780
        }
509 alex-w 1781
        if ($sVersionID != 0) {
1782
            // Режим редактирования
556 alex-w 1783
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$sVersionID."'";
497 alex-w 1784
            $rq =& $this->db->query($query);
1785
            $rq->fetchInto($element);
509 alex-w 1786
        }
1787
 
511 alex-w 1788
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 1789
        if ($sVersionID != 0) {
1790
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
1791
        } else {
1792
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
1793
        }
509 alex-w 1794
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
1795
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
1796
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
1797
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 1798
 
504 alex-w 1799
        return $show;
509 alex-w 1800
    }    
504 alex-w 1801
 
520 alex-w 1802
    /**
1803
     * Парсер схемы адреса репозитория
1804
     * FIXME Возможно не потребуется
1805
     *
1806
     * @author Alexander Wolf
1807
     * @category Core
1808
     *
1809
     * @param string $repstring
1810
     * @return integer
1811
     */
1812
    public function repositoryParser($repstring) {
1813
        $tokens = array();
1814
        $sections = array();
1815
        $tokens = split(" ",$repstring);
1816
 
1817
        if ($tokens[0] == "deb") {
1818
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
1819
            $url = parse_url($tokens[1]);
1820
            $distr  = $tokens[2];
1821
 
1822
            for($i=3;$i<count($tokens);$i++) {
1823
                $sections[] = $tokens[$i];
1824
            }
1825
        } else {
1826
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
1827
            if (stripos($tokens[1],"]")!=0) {
1828
                $sign = $tokens[1];
1829
                $url = parse_url($tokens[2]);
1830
                $base = $tokens[3];
1831
                $repname = $tokens[4];
1832
            } else {
1833
                $url = parse_url($tokens[1]);
1834
                $base = $tokens[2];
1835
                $repname = $tokens[3];
1836
            }
1837
        }
1838
 
1839
        $proto      = $url["scheme"]."://";
1840
        $addr       = $url["host"];
1841
        if ($url["port"]!="") {
1842
            $addr .= ":".$url["port"];
1843
        }
1844
        $path       = $url["path"];
1845
 
1846
        return 0;
1847
    }
1848
 
539 alex-w 1849
    /**
1850
     * Выгрузка картинок логотипов дистрибутивов
1851
     *
1852
     * @author Alexander Wolf
1853
     * @category Core
1854
     *
1855
     * @param string $path
1856
     * @param string $dist
1857
     * @param array $datafile
1858
     * @return integer
1859
     */
535 alex-w 1860
    public function uploadPicture($path, $dist, $datafile) {
1861
        $folder   = $path.$dist."-orig.png";
1862
        $folderN  = $path.$dist.".png";
1863
        $folderEM = $path.$dist."-em.png";
1864
 
1865
        $distlogo = 0;
1866
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
1867
            chmod($folder, 0644);
1868
            list($width, $height) = GetImageSize($folder);
1869
            $percent = 32/$height;
1870
            $newwidth = $width * $percent;
1871
            $newheight = $height * $percent;
1872
 
1873
            $output = ImageCreateTrueColor($newwidth, $newheight);
1874
            $source = ImageCreateFromPNG($folder);
1875
 
1876
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1877
            ImagePNG($output, $folderEM);
1878
 
1879
            $percent = 15/$height;
1880
            $newwidth = $width * $percent;
1881
            $newheight = $height * $percent;
1882
 
1883
            $output = ImageCreateTrueColor($newwidth, $newheight);
1884
 
1885
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1886
            ImagePNG($output, $folderN);
1887
 
1888
            unlink($folder);
1889
            $distlogo = 1;
1890
        }
1891
        return $distlogo;
1892
    }
547 alex-w 1893
 
1894
    /**
1895
     * Показ списка репозиториев
1896
     *
1897
     * @author Alexander Wolf
1898
     * @category Core
1899
     *
1900
     * @param string $name
1901
     * @param string $actor
1902
     * @param string $format
1903
     * @return string
1904
     */
548 alex-w 1905
    public function showRepositoriesList($name, $actor, $format = 'list') {
549 alex-w 1906
        $query  = "SELECT * FROM ".$this->prefix."repository r ";
548 alex-w 1907
        $query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
1908
        $rq =& $this->db->query($query);
1909
        $show = "<ul>";
1910
        while ($rq->fetchInto($element)) {
1911
            $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";
1912
        }
1913
        $show .= "</ul>";
547 alex-w 1914
        return $show;
1915
    }
1916
 
1917
    /**
558 alex-w 1918
     * Вывод списка типов репозиториев
1919
     *
1920
     * @author Alexander Wolf
1921
     * @category Core
1922
     *
1923
     * @param integer $reptype
1924
     * @param string $name
1925
     * @return string
1926
     */
1927
    public function showRepType($reptype = 0, $name = "") {
1928
        $sRT = $this->secure->checkInt($reptype);
1929
        $sNM = $this->secure->checkStr($name,1);
559 alex-w 1930
        $query = "SELECT * FROM ".$this->prefix."rtype";
558 alex-w 1931
        $rq =& $this->db->query($query);
1932
        $show = "<select name='".$sNM."' id='".$sNM."'>\n";
1933
        while ($rq->fetchInto($element)) {
1934
            if ($element["rtype_id"]==$sRT) {
1935
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."' selected>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
1936
            } else {
1937
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."'>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
1938
            }
1939
        }
1940
        $show .= "</select>";
1941
 
1942
        return $show;
1943
    }
1944
 
591 alex-w 1945
    public function showVDList($name, $versionID = 0) {
592 alex-w 1946
        $query  = "SELECT v.version_id, CONCAT(d.distname, ' ', v.version, ' ', v.vname) AS fullname FROM ".$this->prefix."version v ";
591 alex-w 1947
        $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id";
1948
        $rq =& $this->db->query($query);
1949
        $show = "<select name='".$name."' id='".$name."'>\n";
1950
        while ($rq->fetchInto($element)) {
592 alex-w 1951
            if ($element["version_id"]==$versionID) {
1952
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."' selected>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
1953
            } else {
1954
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
1955
            }
591 alex-w 1956
        }
1957
        $show .= "</select>";
1958
        return $show;
1959
    }
1960
 
558 alex-w 1961
    /**
547 alex-w 1962
     * Форма создания/редактирвоания репозиториев
1963
     *
1964
     * @author Alexander Wolf
1965
     * @category Core
1966
     *
1967
     * @param integer $repID
1968
     * @param string $info
1969
     * @param string $reptype
1970
     * @return string
1971
     */
594 alex-w 1972
    public function showRepositoriesForm($repID = 0, $info = "") {
556 alex-w 1973
        $sRepID = $this->secure->checkInt($repID);
594 alex-w 1974
        $sInfo  = $this->secure->checkStr($info, 1);        
556 alex-w 1975
        if ($sInfo == "") {
1976
            $sInfo = "Репозиторий";
1977
        }
1978
        if ($sRepID != 0) {
1979
            // Режим редактирования
591 alex-w 1980
            $query  = "SELECT r.*,v.*,d.dist_id,dt.type FROM ".$this->prefix."repository r ";
556 alex-w 1981
            $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
1982
            $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ";
1983
            $query .= "JOIN ".$this->prefix."dtype dt ON d.disttype=dt.type_id ";
1984
            $query .= "WHERE r.rep_id='".$sRepID."'";
1985
            $rq =& $this->db->query($query);
594 alex-w 1986
            $rq->fetchInto($element);            
556 alex-w 1987
        }
1988
 
594 alex-w 1989
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";        
591 alex-w 1990
        $show .= "<div class='inputbox'><label for='rdist'>Дистрибутив:</label> ".$this->showVDList("rdist",$this->secure->checkInt($element["dist_id"]),"innerhtml")."</div>\n";
556 alex-w 1991
        $show .= "<div class='inputbox'><label for='rname'>Название репозитория:</label> <input type='text' name='rname' value='".$this->secure->checkStr($element["repname"],1)."'></div>\n";
1992
        $show .= "<div class='inputbox'><label for='rinfo'>Описание репозитория:</label> <input type='text' name='rinfo' value='".$this->secure->checkStr($element["repinfo"],1)."'></div>\n";
1993
        $show .= "<div class='inputbox'><label for='rkey'>Ключ подписи репозитория:</label> <input type='text' name='rkey' value='".$this->secure->checkStr($element["repkey"],1)."'></div>\n";
576 alex-w 1994
        $show .= "<div class='inputbox'><label for='rproto'>Протокол доступа:</label> ".$this->showProtoList("rproto",$this->secure->checkInt($element["proto_id"]),"innerhtml")."</div>\n";
588 alex-w 1995
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> ".$this->showHostsList("rhost",$this->secure->checkInt($element["rhost_id"]),"innerhtml")."</div>\n";
590 alex-w 1996
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> ".$this->showFoldersList("rhost",$this->secure->checkInt($element["rfolder_id"]),"innerhtml")."</div>\n";
558 alex-w 1997
        $show .= "<div class='inputbox'><label for='rtype'>Тип репозитория:</label> ".$this->showRepType($this->secure->checkInt($element["rtype_id"]), "rtype")."</div>\n";
564 alex-w 1998
        $show .= "<div class='inputbox'><label for='rsects'>Секции репозитория:</label> <div class='formwrapper'>".$this->showSectionsList("rsects",$sRepID,"innerhtml")."</div></div>\n";
569 alex-w 1999
        $show .= "<div class='inputbox'><label for='rarchs'>Архитектуры:</label> <div class='formwrapper'>".$this->showArchList("rarchs",$sRepID,"innerhtml")."</div></div>\n";
570 alex-w 2000
        $show .= "<div class='inputbox'><label for='rscheme'>Схема репозитория:</label> ".$this->showSchemeList("rscheme",$sRepID,"innerhtml")."</div>\n";
595 alex-w 2001
        $show .= "<div class='inputbox'><label for='rsign'>Подпись репозитория:</label> ".$this->showSignsList("rsign",$this->secure->checkInt($element["sign_id"]),"innerhtml")."</div>\n";
556 alex-w 2002
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
593 alex-w 2003
 
547 alex-w 2004
        return $show;
2005
    }
560 alex-w 2006
 
304 alex-w 2007
}
2008
 
356 alex-w 2009
?>