Хранилища Subversion ant

Редакция

Редакция 667 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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 ";
627 alex-w 272
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."' ";
273
        $query .= "ORDER BY s.sect_id ASC";
317 alex-w 274
        $rq =& $this->db->query($query);
275
        switch ($format) {
276
            case 'html':
277
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
278
                while ($rq->fetchInto($element)) {
493 alex-w 279
                    $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 280
                }
281
                $show .= "</fieldset>\n";
282
                break;
283
            case 'json':
284
                //TODO Доделать JSON-вывод списка секций основного репозитория
285
                break;
286
        }
318 alex-w 287
 
288
        return $show;
317 alex-w 289
    }
290
 
463 alex-w 291
    /**
292
     * Получение и отображение списка репозиториев
293
     *
294
     * @author Alexander Wolf
295
     * @category Core
296
     *
297
     * @param integer $version
298
     * @param integer $reptype
299
     * @param string $format
300
     * @return string
301
     */
368 alex-w 302
    public function showRepList($version, $reptype, $format = 'html') {
606 alex-w 303
        $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
304
        $rq =& $this->db->query($query);
305
        $rq->fetchInto($types);
317 alex-w 306
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
307
        $rq =& $this->db->query($query);
308
        switch ($format) {
309
            case 'html':
607 alex-w 310
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
311
                while ($rq->fetchInto($element)) {
320 alex-w 312
                    $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 313
                }
314
                $show .= "</fieldset>\n";
315
                break;
316
            case 'json':
317
                //TODO Доделать JSON-вывод списка репозиториев
318
                break;
319
        }
318 alex-w 320
 
321
        return $show;
317 alex-w 322
    }
323
 
463 alex-w 324
    /**
325
     * Добавление поддержки нового apt-дистрибутива
326
     *
327
     * @author Alexander Wolf
328
     * @category Core
329
     *
330
     * @param string $distname
331
     * @param integer $disttype
332
     * @param string $distua
333
     * @param byte $distlogo
334
     * @return array
335
     */
514 alex-w 336
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 337
        $result = array();
582 alex-w 338
        $sDName = $this->secure->checkStr($distname);
321 alex-w 339
        $sDType = $this->secure->checkInt($disttype);
582 alex-w 340
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 341
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 342
 
343
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
344
        $rq =& $this->db->query($query);
345
        if (PEAR::isError($this->db)) {
346
            $result["ERR"] = 1;
347
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 348
        } else {            
321 alex-w 349
            $result["ERR"] = 0;
350
        }
351
 
352
        return $result;
353
    }
354
 
463 alex-w 355
    /**
514 alex-w 356
     * Обновление информации о дистрибутиве
357
     *
358
     * @author Alexander Wolf
359
     * @category Core
360
     *
361
     * @param integer $distID
362
     * @param string $distname
363
     * @param integer $disttype
364
     * @param string $distua
365
     * @param integer $distlogo
366
     * @return array
367
     */
538 alex-w 368
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 369
        $result = array();
370
        $sDID   = $this->secure->checkInt($distID);
579 alex-w 371
        $sDName = $this->secure->checkStr($distname);
514 alex-w 372
        $sDType = $this->secure->checkInt($disttype);
579 alex-w 373
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 374
        $sDLogo = $this->secure->checkInt($distlogo);
375
 
538 alex-w 376
        if ($sDLogo!=0) {
377
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
378
        } else {
379
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
380
        }
514 alex-w 381
        $rq =& $this->db->query($query);
382
        if (PEAR::isError($this->db)) {
383
            $result["ERR"] = 1;
384
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 385
        } else {            
514 alex-w 386
            $result["ERR"] = 0;
387
        }
388
 
389
        return $result;
390
    }
391
 
392
    /**
393
     * Удаление информации о дистрибутиве
394
     *
395
     * @author Alexander Wolf
396
     * @category Core
397
     *
398
     * @param integer $distID
399
     * @return array
400
     */
401
    public function dropDistribution($distID) {
402
        $result = array();
403
        $sDID   = $this->secure->checkInt($distID);
404
 
405
        // Удаление дистрибутива
406
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
407
        $rq =& $this->db->query($query);
408
        if (PEAR::isError($this->db)) {
409
            $result["ERR"] = 1;
410
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 411
        } else {            
514 alex-w 412
            $result["ERR"] = 0;
413
        }
414
 
415
        // Удаление версий дистрибутива
416
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
417
        $rq =& $this->db->query($query);
418
        if (PEAR::isError($this->db)) {
419
            $result["ERR"] = 1;
420
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 421
        } else {            
514 alex-w 422
            $result["ERR"] = 0;
423
        }
424
 
425
        return $result;
426
    }
427
 
428
    /**
463 alex-w 429
     * Добавление поддержки новой версии apt-дистрибутива
430
     *
431
     * @author Alexander Wolf
432
     * @category Core
433
     *
434
     * @param integer $distID
435
     * @param integer $version
436
     * @param string $vname
437
     * @param integer $vcodename
438
     * @return array
439
     */
368 alex-w 440
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 441
        $result = array();
463 alex-w 442
        $sDistID    = $this->secure->checkInt($distID);
582 alex-w 443
        $sDVersion  = $this->secure->checkStr($version);
444
        $sDVName    = $this->secure->checkStr($vname);
445
        $sDVCName   = $this->secure->checkStr($vcodename);
356 alex-w 446
 
447
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
448
        $rq =& $this->db->query($query);
449
        if (PEAR::isError($this->db)) {
450
            $result["ERR"] = 1;
451
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 452
        } else {            
356 alex-w 453
            $result["ERR"] = 0;
454
        }
455
 
456
        return $result;
457
    }
358 alex-w 458
 
463 alex-w 459
    /**
514 alex-w 460
     * Редактирование информации о версии дистрибутива
461
     *
462
     * @author Alexander Wolf
463
     * @category Core
464
     *
465
     * @param integer $versionID
466
     * @param string $version
467
     * @param string $vname
468
     * @param string $vcodename
469
     * @return array
470
     */
471
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
472
        $result = array();
473
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 474
        $sDVersion  = $this->secure->checkStr($version,1);
475
        $sDVName    = $this->secure->checkStr($vname,1);
476
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 477
 
478
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
479
        $rq =& $this->db->query($query);
480
        if (PEAR::isError($this->db)) {
481
            $result["ERR"] = 1;
482
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 483
        } else {            
514 alex-w 484
            $result["ERR"] = 0;
485
        }
486
 
487
        return $result;
488
    }
489
 
490
    /**
491
     * Удаление информации о версии дистрибутива
492
     *
493
     * @author Alexander Wolf
494
     * @category Core
495
     *
496
     * @param integer $versionID
497
     * @return array
498
     */
499
    public function dropDistVersion($versionID) {
500
        $result = array();
501
        $sVersID    = $this->secure->checkInt($versionID);
502
 
503
        // Удаление версии дистрибутива
504
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
505
        $rq =& $this->db->query($query);
506
        if (PEAR::isError($this->db)) {
507
            $result["ERR"] = 1;
508
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 509
        } else {            
514 alex-w 510
            $result["ERR"] = 0;
511
        }
512
 
513
        // Удаление репозиториев этой версии дистрибутива
514
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
515
        $rq =& $this->db->query($query);
516
        if (PEAR::isError($this->db)) {
517
            $result["ERR"] = 1;
518
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 519
        } else {            
514 alex-w 520
            $result["ERR"] = 0;
521
        }
522
 
523
        return $result;
524
    }
525
 
526
    /**
463 alex-w 527
     * Отображение типа дистрибутива
528
     *
529
     * @author Alexander Wolf
530
     * @category Core
531
     *
532
     * @param string $name
533
     * @param byte $type
534
     * @return string
535
     */
368 alex-w 536
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 537
        $query = "SELECT * FROM ".$this->prefix."dtype";
538
        $rq =& $this->db->query($query);
539
        $show = "<select name='".$name."' id='".$name."'>\n";
540
        while ($rq->fetchInto($element)) {
347 alex-w 541
            if ($element["type_id"] == $type) {
542
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 543
            } else {
347 alex-w 544
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 545
            }
546
        }
547
        $show .= "</select>";
548
 
549
        return $show;
550
    }
551
 
463 alex-w 552
    /**
553
     * Отображение формы создания и редактирования apt-дистрибутива
554
     *
555
     * @author Alexander Wolf
556
     * @category Core
557
     *
558
     * @param integer $distID
559
     * @return string
560
     */
511 alex-w 561
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 562
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 563
        $sInfo = $this->secure->checkStr($info, 1);
564
        if ($sInfo == "") {
565
            $sInfo = "Дистрибутив";
566
        }
329 alex-w 567
        if ($sDistID != 0) {
568
            // Режим редактирования
569
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
570
            $rq =& $this->db->query($query);
571
            $rq->fetchInto($element);
572
        }
573
 
574
        if ($element["distlogo"] == 1) {
380 alex-w 575
            $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 576
        } else {
380 alex-w 577
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 578
        }
579
 
511 alex-w 580
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 581
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
582
        $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 583
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 584
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 585
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 586
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 587
 
588
        return $show;
589
    }
590
 
628 alex-w 591
    /**
592
     * Генератор sources.list
593
     *
594
     * @author Alexander Wolf
595
     * @category Core
596
     * @version 1.0
597
     *
598
     * @param array $data
599
     * @return string
600
     */
668 alex-w 601
    public function showSourcesList($data) {      
646 alex-w 602
       // Извлекаем информацию о дистрибутиве и его версии
603
       $query  = "SELECT * FROM ".$this->prefix."distribution d ";
649 alex-w 604
       $query .= "JOIN ".$this->prefix."version v ON v.dist_id=d.dist_id ";
646 alex-w 605
       $query .= "JOIN ".$this->prefix."dtype t ON d.disttype=t.type_id ";
648 alex-w 606
       $query .= "WHERE d.dist_id='".$data["dist_id"]."' AND v.version_id='".$data["version_id"]."'";
646 alex-w 607
       $rq =& $this->db->query($query);
608
       $rq->fetchInto($dist);
663 alex-w 609
 
653 alex-w 610
       $show = "# Список репозиториев для ".$this->secure->checkStr($dist["distname"],1)." ".$this->secure->checkStr($dist["version"],1)." ".$this->secure->checkStr($dist["vname"],1)."\n\n";
646 alex-w 611
 
612
       // Извлекаем информацию о репозиториях и строим sources.list
613
       if ($dist["type"]=="deb") {
614
           // Базовый репозиторий
615
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
616
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
617
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
651 alex-w 618
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
646 alex-w 619
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
620
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
621
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
650 alex-w 622
           $query .= "WHERE v.version_id='".$data["version_id"]."' AND r.rtype_id='1'";
646 alex-w 623
           $rq =& $this->db->query($query);
624
           $rq->fetchInto($base);
625
           // Формируем type proto://host/folder
659 alex-w 626
           $show .= "# ".$this->secure->checkStr($base["repinfo"],1)."\n";
654 alex-w 627
           $show .= $this->secure->checkStr($dist["type"],1)." ".$this->secure->checkStr($base["proto"],1).$this->secure->checkStr($base["rhost"],1).$this->secure->checkStr($base["rfolder"],1);
628
           $dvname = str_replace("{DIST}",$this->secure->checkStr($dist["vcodename"],1),$this->secure->checkStr($base["scheme"],1));
646 alex-w 629
           // Формируем distname
630
           $show .= " ".$dvname." ";
631
           // Формируем sections
632
           $query  = "SELECT * FROM ".$this->prefix."section s ";
633
           $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
634
           $query .= "WHERE r.rep_id='".$base["rep_id"]."' AND (";
635
           for($i=0;$i<count($data["section"]);$i++) {
652 alex-w 636
               $query .= "s.sect_id='".$data["section"][$i]."' ";
646 alex-w 637
               if ($i<count($data["section"])-1) {
638
                   $query .= " OR ";
639
               }
640
           }
641
           $query .= ")";
642
           $rq =& $this->db->query($query);
643
           while ($rq->fetchInto($sections)) {
644
               $show .= $sections["secname"]." ";
645
           }
655 alex-w 646
           $show .= "\n\n";
647
 
658 alex-w 648
           // Репозитории обновлений и третьих лиц
655 alex-w 649
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
650
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
651
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
652
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
653
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
654
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
655
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
658 alex-w 656
           $query .= "WHERE r.rtype_id>'1' AND (";
656 alex-w 657
           for($i=0;$i<count($data["repository"]);$i++) {
658
                $query .= "r.rep_id='".$data["repository"][$i]."' ";
659
                    if ($i<count($data["repository"])-1) {
660
                        $query .= " OR ";
661
                    }
662
                }
666 alex-w 663
           $query .= ") ORDER BY r.rtype_id ASC";          
667 alex-w 664
           $req =& $this->db->query($query);
665
           while ($req->fetchInto($updates)) {
655 alex-w 666
                // Формируем type proto://host/folder
659 alex-w 667
                $show .= "# ".$this->secure->checkStr($updates["repinfo"],1)."\n";
655 alex-w 668
                $show .= $this->secure->checkStr($dist["type"],1)." ".$this->secure->checkStr($updates["proto"],1).$this->secure->checkStr($updates["rhost"],1).$this->secure->checkStr($updates["rfolder"],1);
669
                $dvname = str_replace("{DIST}",$this->secure->checkStr($dist["vcodename"],1),$this->secure->checkStr($updates["scheme"],1));
670
                // Формируем distname
671
                $show .= " ".$dvname." ";
672
                // Формируем sections
673
                $query  = "SELECT * FROM ".$this->prefix."section s ";
674
                $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
661 alex-w 675
                $query .= "WHERE r.rep_id='".$updates["rep_id"]."'";
655 alex-w 676
                $rq =& $this->db->query($query);
677
                while ($rq->fetchInto($sections)) {
678
                    $show .= $sections["secname"]." ";
679
                }
668 alex-w 680
                $show .= "\n\n";
655 alex-w 681
           }
646 alex-w 682
           $show .= "\n";
668 alex-w 683
       } else {
684
           // Базовый репозиторий
685
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
686
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
687
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
688
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
689
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
690
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
691
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";          
692
           $query .= "WHERE v.version_id='".$data["version_id"]."' AND r.rtype_id='1'";
693
           $rq =& $this->db->query($query);
694
           $rq->fetchInto($base);
695
           // Формируем type proto://host/folder
696
           $show .= "# ".$this->secure->checkStr($base["repinfo"],1)."\n";
697
           $show .= $this->secure->checkStr($dist["type"],1)." ";
698
           if ($base["sign_id"]!=0) {
699
               $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$base["sign_id"]."'";
700
               $rq =& $this->db->query($query);
701
               $rq->fetchInto($sign);
702
               $show .= "[".$this->secure->checkStr($sign["sign"],1)."] ";
703
           }
704
           $show .= $this->secure->checkStr($base["proto"],1).$this->secure->checkStr($base["rhost"],1).$this->secure->checkStr($base["rfolder"],1)." ";
705
           $show .= $this->secure->checkStr($base["scheme"],1);
646 alex-w 706
 
668 alex-w 707
           // Формируем sections
708
           $query  = "SELECT * FROM ".$this->prefix."section s ";
709
           $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
710
           $query .= "WHERE r.rep_id='".$base["rep_id"]."' AND (";
711
           for($i=0;$i<count($data["section"]);$i++) {
712
               $query .= "s.sect_id='".$data["section"][$i]."' ";
713
               if ($i<count($data["section"])-1) {
714
                   $query .= " OR ";
715
               }
716
           }
717
           $query .= ")";
718
           $rq =& $this->db->query($query);
719
           while ($rq->fetchInto($sections)) {
720
               $show .= $sections["secname"]." ";
721
           }
722
           $show .= "\n\n";
723
 
724
           // Репозитории обновлений и третьих лиц
725
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
726
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
727
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
728
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
729
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
730
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
731
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
732
           $query .= "WHERE r.rtype_id>'1' AND (";
733
           for($i=0;$i<count($data["repository"]);$i++) {
734
                $query .= "r.rep_id='".$data["repository"][$i]."' ";
735
                    if ($i<count($data["repository"])-1) {
736
                        $query .= " OR ";
737
                    }
738
                }
739
           $query .= ") ORDER BY r.rtype_id ASC";
740
           $req =& $this->db->query($query);
741
           while ($req->fetchInto($updates)) {
742
                // Формируем type proto://host/folder
743
                $show .= "# ".$this->secure->checkStr($updates["repinfo"],1)."\n";
744
                $show .= $this->secure->checkStr($dist["type"],1)." ";
745
                if ($updates["sign_id"]!=0) {
746
                    $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$base["sign_id"]."'";
747
                    $rqs =& $this->db->query($query);
748
                    $rqs->fetchInto($sign);
749
                    $show .= "[".$this->secure->checkStr($sign["sign"],1)."] ";
750
                }
751
                $show .= $this->secure->checkStr($updates["proto"],1).$this->secure->checkStr($updates["rhost"],1).$this->secure->checkStr($updates["rfolder"],1)." ";
752
                $show .= $this->secure->checkStr($updates["scheme"],1);
753
                // Формируем sections
754
                $query  = "SELECT * FROM ".$this->prefix."section s ";
755
                $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
756
                $query .= "WHERE r.rep_id='".$updates["rep_id"]."'";
757
                $rq =& $this->db->query($query);
758
                while ($rq->fetchInto($sections)) {
759
                    $show .= $sections["secname"]." ";
760
                }
761
                $show .= "\n\n";
762
           }
763
           $show .= "\n";
646 alex-w 764
       }
765
 
668 alex-w 766
       $HTTPHeader1 = "Content-length: ".strlen($show);
767
       $HTTPHeader2 = "Content-disposition: attachment; filename=sources.list\n\n";
768
 
769
       header($HTTPHeader1);
770
       header($HTTPHeader2);
628 alex-w 771
       return $show;
358 alex-w 772
    }
522 alex-w 773
 
463 alex-w 774
    /**
522 alex-w 775
     * Показывает список секций
776
     *
777
     * @author Alexander Wolf
778
     * @category Core
779
     *
780
     * @param string $name
781
     * @param string $actor
561 alex-w 782
     * @param string $format
522 alex-w 783
     * @return string
784
     */
560 alex-w 785
    public function showSectionsList($name, $actor, $format = 'html') {
786
        switch($format) {
787
            case 'html':
561 alex-w 788
                $query = "SELECT * FROM ".$this->prefix."section";
789
                $rq =& $this->db->query($query);
560 alex-w 790
                $show = "<ul>\n";
791
                while ($rq->fetchInto($element)) {
792
                    $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";
793
                }
794
                $show .= "</ul>";
795
                break;
796
            case 'innerhtml':
797
                $show = "";
561 alex-w 798
                $repID = $this->secure->checkInt($actor);
799
                if ($repID==0) {
800
                    $query = "SELECT * FROM ".$this->prefix."section";
801
                    $rq =& $this->db->query($query);
802
                    while ($rq->fetchInto($element)) {
567 alex-w 803
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 804
                    }
805
                } else {
806
                    $query = "SELECT * FROM ".$this->prefix."section s JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$repID'";
807
                    $rq =& $this->db->query($query);
808
                    while ($rq->fetchInto($element)) {
567 alex-w 809
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."' checked>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 810
                    }
811
                    $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 812
                    $rq =& $this->db->query($query);
561 alex-w 813
                    while ($rq->fetchInto($element)) {
567 alex-w 814
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 815
                    }
816
                }
817
 
560 alex-w 818
                break;
522 alex-w 819
        }
820
 
821
        return $show;
822
    }
823
 
523 alex-w 824
    /**
825
     * Вывод формы редактирования/добавления секций
826
     *
827
     * @author Alexander Wolf
828
     * @category Core
829
     *
830
     * @param integer $sectionID
831
     * @param string $info
832
     * @return string
833
     */
834
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 835
        $sSectID = $this->secure->checkInt($sectionID);
836
        $sInfo = $this->secure->checkStr($info, 1);
837
        if ($sInfo == "") {
838
            $sInfo = "Секция";
839
        }
840
        if ($sSectID != 0) {
841
            // Режим редактирования
842
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
843
            $rq =& $this->db->query($query);
844
            $rq->fetchInto($element);
845
        }
846
 
847
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
848
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
849
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
850
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
851
 
852
        return $show;
853
    }
854
 
855
    /**
523 alex-w 856
     * Обновление информации о секции
857
     *
858
     * @author Alexander Wolf
859
     * @category Core
860
     *
861
     * @param integer $sectionID
862
     * @param string $sname
863
     * @param string $sinfo
864
     * @return array
865
     */
866
    public function updateSection($sectionID, $sname, $sinfo = "") {
867
        $result = array();
868
        $sSectID    = $this->secure->checkInt($sectionID);
579 alex-w 869
        $sSName     = $this->secure->checkStr($sname);
870
        $sSInfo     = $this->secure->checkStr($sinfo);
523 alex-w 871
 
872
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
873
        $rq =& $this->db->query($query);
874
        if (PEAR::isError($this->db)) {
875
            $result["ERR"] = 1;
876
            $result["ERRINFO"] = $this->db->getMessage();
877
        } else {
878
            $result["ERR"] = 0;
879
        }
880
 
881
        return $result;
882
    }
883
 
884
    /**
885
     * Удаление информации о секции
886
     *
887
     * @author Alexander Wolf
888
     * @category Core
889
     *
890
     * @param integer $sectionID
891
     * @return array
892
     */
893
    public function dropSection($sectionID) {
894
        $result = array();
895
        $sSectID    = $this->secure->checkInt($sectionID);
896
 
897
        // Удаление секции
898
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
899
        $rq =& $this->db->query($query);
900
        if (PEAR::isError($this->db)) {
901
            $result["ERR"] = 1;
902
            $result["ERRINFO"] = $this->db->getMessage();
903
        } else {
904
            $result["ERR"] = 0;
905
        }
906
 
907
        return $result;
908
    }
909
 
910
    /**
911
     * Добавление новой секции
912
     *
913
     * @author Alexander Wolf
914
     * @category Core
915
     *
916
     * @param string $sname
917
     * @param string $sinfo
918
     * @return array
919
     */
920
    public function addSection($sname, $sinfo = "") {
921
        $result = array();
582 alex-w 922
        $sSName = $this->secure->checkStr($sname);
923
        $sSInfo = $this->secure->checkStr($sinfo);
523 alex-w 924
 
925
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
926
        $rq =& $this->db->query($query);
927
        if (PEAR::isError($this->db)) {
928
            $result["ERR"] = 1;
929
            $result["ERRINFO"] = $this->db->getMessage();
930
        } else {
931
            $result["ERR"] = 0;
932
        }
933
 
934
        return $result;
935
    }
936
 
937
    /**
568 alex-w 938
     * Вывод списка поддерживаемых архитектур
939
     *
940
     * @author Alexander Wolf
941
     * @category Core
942
     *
943
     * @param string $name
944
     * @param string $actor
945
     * @param string $format
946
     * @return string
947
     */
948
    public function showArchList($name, $actor, $format = 'list') {
949
        switch($format) {
950
            case 'list':
951
                $query = "SELECT * FROM ".$this->prefix."arch";
952
                $rq =& $this->db->query($query);
953
                $show = "<ul>\n";
954
                while ($rq->fetchInto($element)) {
955
                    $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";
956
                }
957
                $show .= "</ul>";
958
                break;
959
            case 'innerhtml':
960
                $show = "";
961
                $repID = $this->secure->checkInt($actor);
614 alex-w 962
                if ($repID==0) {
568 alex-w 963
                    $query = "SELECT * FROM ".$this->prefix."arch";
964
                    $rq =& $this->db->query($query);
965
                    while ($rq->fetchInto($element)) {
966
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
967
                    }
968
                } else {
969
                    $query = "SELECT * FROM ".$this->prefix."arch a JOIN ".$this->prefix."arch2rep r ON a.arch_id=r.arch_id WHERE r.rep_id='$repID'";
970
                    $rq =& $this->db->query($query);
971
                    while ($rq->fetchInto($element)) {
972
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."' checked>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
973
                    }
974
                    $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')";
975
                    $rq =& $this->db->query($query);
610 alex-w 976
                    if ($rq->numRows()>0) {
977
                        while ($rq->fetchInto($element)) {
978
                            $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
979
                        }
568 alex-w 980
                    }
981
                }
982
                break;
983
        }
984
        return $show;
985
    }
986
 
987
    /**
988
     * Добавление новой архитектуры
989
     *
990
     * @author Alexander Wolf
991
     * @category Core
992
     *
993
     * @param string $arch
994
     * @return array
995
     */
996
    public function addArch($arch) {
997
        $result = array();
582 alex-w 998
        $sArch = $this->secure->checkStr($arch);
568 alex-w 999
 
1000
        $query = "INSERT INTO ".$this->prefix."arch SET arch='".$sArch."'";
1001
        $rq =& $this->db->query($query);
1002
        if (PEAR::isError($this->db)) {
1003
            $result["ERR"] = 1;
1004
            $result["ERRINFO"] = $this->db->getMessage();
1005
        } else {
1006
            $result["ERR"] = 0;
1007
        }
1008
 
1009
        return $result;
1010
    }
1011
 
1012
    /**
1013
     * Удаление информации об архитектуре
1014
     *
1015
     * @author Alexander Wolf
1016
     * @category Core
1017
     *
1018
     * @param integer $archID
1019
     * @return array
1020
     */
1021
    public function dropArch($archID) {
1022
        $result = array();
1023
        $sArchID    = $this->secure->checkInt($archID);
1024
 
1025
        // Удаление архитектуры
1026
        $query = "DELETE FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
1027
        $rq =& $this->db->query($query);
1028
        if (PEAR::isError($this->db)) {
1029
            $result["ERR"] = 1;
1030
            $result["ERRINFO"] = $this->db->getMessage();
1031
        } else {
1032
            $result["ERR"] = 0;
1033
        }
1034
 
1035
        // Удаление архитектуры из списка репозиториев
1036
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE arch_id='".$sArchID."'";
1037
        $rq =& $this->db->query($query);
1038
        if (PEAR::isError($this->db)) {
1039
            $result["ERR"] = 1;
1040
            $result["ERRINFO"] = $this->db->getMessage();
1041
        } else {
1042
            $result["ERR"] = 0;
1043
        }
1044
        return $result;
1045
    }
1046
 
1047
    /**
1048
     * Обновление информации об архитектуре
1049
     *
1050
     * @author Alexander Wolf
1051
     * @category Core
1052
     *
1053
     * @param integer $archID
1054
     * @param string $arch
1055
     * @return array
1056
     */
1057
    public function updateArch($archID, $arch) {
1058
        $result = array();
1059
        $sArchID    = $this->secure->checkInt($archID);
579 alex-w 1060
        $sArch      = $this->secure->checkStr($arch);
568 alex-w 1061
 
1062
        $query = "UPDATE ".$this->prefix."arch SET arch='".$sArch."' WHERE arch_id='".$sArchID."'";
1063
        $rq =& $this->db->query($query);
1064
        if (PEAR::isError($this->db)) {
1065
            $result["ERR"] = 1;
1066
            $result["ERRINFO"] = $this->db->getMessage();
1067
        } else {
1068
            $result["ERR"] = 0;
1069
        }
1070
 
1071
        return $result;
1072
    }
1073
 
1074
    /**
1075
     * Вывод формы редактирования/добавления архитектур
1076
     *
1077
     * @author Alexander Wolf
1078
     * @category Core
1079
     *
1080
     * @param integer $archID
1081
     * @param string $info
1082
     * @return string
1083
     */
1084
    public function showArchForm($archID = 0, $info = "") {
1085
        $sArchID = $this->secure->checkInt($archID);
1086
        $sInfo = $this->secure->checkStr($info, 1);
1087
        if ($sInfo == "") {
1088
            $sInfo = "Архитектура";
1089
        }
1090
        if ($sArchID != 0) {
1091
            // Режим редактирования
1092
            $query = "SELECT * FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
1093
            $rq =& $this->db->query($query);
1094
            $rq->fetchInto($element);
1095
        }
1096
 
1097
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1098
        $show .= "<div class='inputbox'><label for='arch'>Архитектура:</label> <input type='text' name='arch' id='arch' value='".$this->secure->checkStr($element["arch"],1)."'></div>\n";
1099
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1100
 
1101
        return $show;
1102
    }
1103
 
1104
    /**
570 alex-w 1105
     * Вывод списка схем репозиториев
1106
     *
1107
     * @author Alexander Wolf
1108
     * @category Core
1109
     *
1110
     * @param string $name
1111
     * @param string $actor
1112
     * @param string $format
1113
     * @return string
1114
     */
1115
    public function showSchemeList($name, $actor, $format = 'list') {
1116
        switch($format) {
1117
            case 'list':
1118
                $query = "SELECT * FROM ".$this->prefix."repscheme";
1119
                $rq =& $this->db->query($query);
1120
                $show = "<ul>\n";
1121
                while ($rq->fetchInto($element)) {
1122
                    $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";
1123
                }
1124
                $show .= "</ul>";
1125
                break;
1126
            case 'innerhtml':
611 alex-w 1127
                $schemeID = $this->secure->checkInt($actor);
570 alex-w 1128
                $query = "SELECT * FROM ".$this->prefix."repscheme";
1129
                $rq =& $this->db->query($query);
1130
                $show = "<select name='".$name."' id='".$name."'>\n";
1131
                while ($rq->fetchInto($element)) {
611 alex-w 1132
                    if ($element["scheme_id"]==$schemeID) {
570 alex-w 1133
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."' selected>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
1134
                    } else {
611 alex-w 1135
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."'>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
570 alex-w 1136
                    }
1137
                }
1138
                $show .= "</select>";
1139
                break;
1140
        }
1141
        return $show;
1142
    }
1143
 
1144
    /**
1145
     * Добавление новой схемы репозитория
1146
     *
1147
     * @author Alexander Wolf
1148
     * @category Core
1149
     *
1150
     * @param string $scheme
1151
     * @return array
1152
     */
1153
    public function addScheme($scheme) {
1154
        $result = array();
582 alex-w 1155
        $sScheme = $this->secure->checkStr($scheme);
570 alex-w 1156
 
1157
        $query = "INSERT INTO ".$this->prefix."repscheme SET scheme='".$sScheme."'";
1158
        $rq =& $this->db->query($query);
1159
        if (PEAR::isError($this->db)) {
1160
            $result["ERR"] = 1;
1161
            $result["ERRINFO"] = $this->db->getMessage();
1162
        } else {
1163
            $result["ERR"] = 0;
1164
        }
1165
 
1166
        return $result;
1167
    }
1168
 
1169
    /**
1170
     * Удаление информации о схеме репозитория
1171
     *
1172
     * @author Alexander Wolf
1173
     * @category Core
1174
     *
1175
     * @param integer $schemeID
1176
     * @return array
1177
     */
1178
    public function dropScheme($schemeID) {
1179
        $result = array();
1180
        $sSchemeID    = $this->secure->checkInt($schemeID);
1181
 
1182
        // Удаление схемы
1183
        $query = "DELETE FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1184
        $rq =& $this->db->query($query);
1185
        if (PEAR::isError($this->db)) {
1186
            $result["ERR"] = 1;
1187
            $result["ERRINFO"] = $this->db->getMessage();
1188
        } else {
1189
            $result["ERR"] = 0;
1190
        }
1191
 
1192
        return $result;
1193
    }
1194
 
1195
    /**
1196
     * Обновление информации о схеме репозитория
1197
     *
1198
     * @author Alexander Wolf
1199
     * @category Core
1200
     *
1201
     * @param integer $schemeID
1202
     * @param string $info
1203
     * @return array
1204
     */
1205
    public function updateScheme($schemeID, $info) {
1206
        $result = array();
1207
        $sSchemeID    = $this->secure->checkInt($schemeID);
579 alex-w 1208
        $sScheme      = $this->secure->checkStr($info);
570 alex-w 1209
 
1210
        $query = "UPDATE ".$this->prefix."repscheme SET scheme='".$sScheme."' WHERE scheme_id='".$sSchemeID."'";
1211
        $rq =& $this->db->query($query);
1212
        if (PEAR::isError($this->db)) {
1213
            $result["ERR"] = 1;
1214
            $result["ERRINFO"] = $this->db->getMessage();
1215
        } else {
1216
            $result["ERR"] = 0;
1217
        }
1218
 
1219
        return $result;
1220
    }
1221
 
1222
    /**
1223
     * Вывод формы редактирования/добавления схем репозиториев
1224
     *
1225
     * @author Alexander Wolf
1226
     * @category Core
1227
     *
1228
     * @param integer $schemeID
1229
     * @param string $info
1230
     * @return string
1231
     */
1232
    public function showSchemeForm($schemeID = 0, $info = "") {
1233
        $sSchemeID = $this->secure->checkInt($schemeID);
1234
        $sInfo = $this->secure->checkStr($info, 1);
1235
        if ($sInfo == "") {
1236
            $sInfo = "Схема репозитория";
1237
        }
571 alex-w 1238
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
570 alex-w 1239
        if ($sSchemeID != 0) {
1240
            // Режим редактирования
1241
            $query = "SELECT * FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1242
            $rq =& $this->db->query($query);
573 alex-w 1243
            $rq->fetchInto($element);            
1244
        }
571 alex-w 1245
 
573 alex-w 1246
        $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 1247
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1248
 
1249
        return $show;
1250
    }
1251
 
1252
    /**
574 alex-w 1253
     * Вывод списка протоколов
1254
     *
1255
     * @author Alexander Wolf
1256
     * @category Core
1257
     *
1258
     * @param string $name
1259
     * @param string $actor
1260
     * @param string $format
1261
     * @return string
1262
     */
1263
    public function showProtoList($name, $actor, $format = 'list') {
1264
        switch($format) {
1265
            case 'list':
1266
                $query = "SELECT * FROM ".$this->prefix."protos";
1267
                $rq =& $this->db->query($query);
1268
                $show = "<ul>\n";
1269
                while ($rq->fetchInto($element)) {
1270
                    $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";
1271
                }
1272
                $show .= "</ul>";
1273
                break;
1274
            case 'innerhtml':
1275
                $protoID = $this->secure->checkInt($actor);
1276
                $query = "SELECT * FROM ".$this->prefix."protos";
1277
                $rq =& $this->db->query($query);
1278
                $show = "<select name='".$name."' id='".$name."'>\n";
1279
                while ($rq->fetchInto($element)) {
1280
                    if ($element["proto_id"]==$protoID) {
1281
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."' selected>".$this->secure->checkStr($element["proto"],1)."</option>\n";
1282
                    } else {
580 alex-w 1283
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."'>".$this->secure->checkStr($element["proto"],1)."</option>\n";
574 alex-w 1284
                    }
1285
                }
1286
                $show .= "</select>";
1287
                break;
1288
        }
1289
        return $show;
1290
    }
1291
 
1292
    /**
1293
     * Добавление нового протокола
1294
     *
1295
     * @author Alexander Wolf
1296
     * @category Core
1297
     *
1298
     * @param string $proto
1299
     * @return array
1300
     */
1301
    public function addProto($proto) {
1302
        $result = array();
582 alex-w 1303
        $sProto = $this->secure->checkStr($proto);
574 alex-w 1304
 
1305
        $query = "INSERT INTO ".$this->prefix."protos SET proto='".$sProto."'";
1306
        $rq =& $this->db->query($query);
1307
        if (PEAR::isError($this->db)) {
1308
            $result["ERR"] = 1;
1309
            $result["ERRINFO"] = $this->db->getMessage();
1310
        } else {
1311
            $result["ERR"] = 0;
1312
        }
1313
 
1314
        return $result;
1315
    }
1316
 
1317
    /**
1318
     * Удаление информации о протоколе
1319
     *
1320
     * @author Alexander Wolf
1321
     * @category Core
1322
     *
1323
     * @param integer $protoID
1324
     * @return array
1325
     */
1326
    public function dropProto($protoID) {
1327
        $result = array();
1328
        $sProtoID    = $this->secure->checkInt($protoID);
1329
 
1330
        // Удаление протокола
1331
        $query = "DELETE FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1332
        $rq =& $this->db->query($query);
1333
        if (PEAR::isError($this->db)) {
1334
            $result["ERR"] = 1;
1335
            $result["ERRINFO"] = $this->db->getMessage();
1336
        } else {
1337
            $result["ERR"] = 0;
1338
        }
1339
 
1340
        return $result;
1341
    }
1342
 
1343
    /**
1344
     * Обновление информации о протоколе
1345
     *
1346
     * @author Alexander Wolf
1347
     * @category Core
1348
     *
1349
     * @param integer $protoID
1350
     * @param string $info
1351
     * @return array
1352
     */
1353
    public function updateProto($protoID, $info) {
1354
        $result = array();
1355
        $sProtoID    = $this->secure->checkInt($protoID);
579 alex-w 1356
        $sProto      = $this->secure->checkStr($info);
574 alex-w 1357
 
1358
        $query = "UPDATE ".$this->prefix."protos SET proto='".$sProto."' WHERE proto_id='".$sProtoID."'";
1359
        $rq =& $this->db->query($query);
1360
        if (PEAR::isError($this->db)) {
1361
            $result["ERR"] = 1;
1362
            $result["ERRINFO"] = $this->db->getMessage();
1363
        } else {
1364
            $result["ERR"] = 0;
1365
        }
1366
 
1367
        return $result;
1368
    }
1369
 
1370
    /**
1371
     * Вывод формы редактирования/добавления протоколов
1372
     *
1373
     * @author Alexander Wolf
1374
     * @category Core
1375
     *
1376
     * @param integer $protoID
1377
     * @param string $info
1378
     * @return string
1379
     */
1380
    public function showProtoForm($protoID = 0, $info = "") {
1381
        $sProtoID = $this->secure->checkInt($protoID);
1382
        $sInfo = $this->secure->checkStr($info, 1);
1383
        if ($sInfo == "") {
1384
            $sInfo = "Протокол доступа";
1385
        }
1386
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1387
        if ($sProtoID != 0) {
1388
            // Режим редактирования
1389
            $query = "SELECT * FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1390
            $rq =& $this->db->query($query);
1391
            $rq->fetchInto($element);
1392
        }
1393
 
1394
        $show .= "<div class='inputbox'><label for='proto'>Протокол доступа:</label> <input type='text' name='proto' id='proto' value='".$this->secure->checkStr($element["proto"],1)."'></div>\n";
1395
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1396
 
1397
        return $show;
1398
    }
1399
 
1400
    /**
582 alex-w 1401
     * Вывод списка хостов
1402
     *
1403
     * @author Alexander Wolf
1404
     * @category Core
1405
     *
1406
     * @param string $name
1407
     * @param string $actor
1408
     * @param string $format
1409
     * @return string
1410
     */
1411
    public function showHostsList($name, $actor, $format = 'list') {
1412
        switch($format) {
1413
            case 'list':
1414
                $query = "SELECT * FROM ".$this->prefix."rephost";
1415
                $rq =& $this->db->query($query);
1416
                $show = "<ul>\n";
1417
                while ($rq->fetchInto($element)) {
1418
                    $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";
1419
                }
1420
                $show .= "</ul>";
1421
                break;
1422
            case 'innerhtml':
1423
                $hostID = $this->secure->checkInt($actor);
1424
                $query = "SELECT * FROM ".$this->prefix."rephost";
1425
                $rq =& $this->db->query($query);
1426
                $show = "<select name='".$name."' id='".$name."'>\n";
1427
                while ($rq->fetchInto($element)) {
1428
                    if ($element["rhost_id"]==$hostID) {
1429
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."' selected>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1430
                    } else {
1431
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."'>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1432
                    }
1433
                }
1434
                $show .= "</select>";
1435
                break;
1436
        }
1437
        return $show;
1438
    }
1439
 
1440
    /**
1441
     * Добавление нового хоста
1442
     *
1443
     * @author Alexander Wolf
1444
     * @category Core
1445
     *
1446
     * @param string $host
1447
     * @return array
1448
     */
1449
    public function addHost($host) {
1450
        $result = array();
1451
        $sHost = $this->secure->checkStr($host);
1452
 
586 alex-w 1453
        $query = "INSERT INTO ".$this->prefix."rephost SET rhost='".$sHost."'";
582 alex-w 1454
        $rq =& $this->db->query($query);
1455
        if (PEAR::isError($this->db)) {
1456
            $result["ERR"] = 1;
1457
            $result["ERRINFO"] = $this->db->getMessage();
1458
        } else {
1459
            $result["ERR"] = 0;
1460
        }
1461
 
1462
        return $result;
1463
    }
1464
 
1465
    /**
1466
     * Удаление информации о хосте
1467
     *
1468
     * @author Alexander Wolf
1469
     * @category Core
1470
     *
1471
     * @param integer $hostID
1472
     * @return array
1473
     */
1474
    public function dropHost($hostID) {
1475
        $result = array();
1476
        $sHostID    = $this->secure->checkInt($hostID);
1477
 
1478
        // Удаление хоста
1479
        $query = "DELETE FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1480
        $rq =& $this->db->query($query);
1481
        if (PEAR::isError($this->db)) {
1482
            $result["ERR"] = 1;
1483
            $result["ERRINFO"] = $this->db->getMessage();
1484
        } else {
1485
            $result["ERR"] = 0;
1486
        }
1487
 
1488
        return $result;
1489
    }
1490
 
1491
    /**
1492
     * Обновление информации о хосте
1493
     *
1494
     * @author Alexander Wolf
1495
     * @category Core
1496
     *
1497
     * @param integer $hostID
1498
     * @param string $info
1499
     * @return array
1500
     */
1501
    public function updateHost($hostID, $info) {
1502
        $result = array();
1503
        $sHostID    = $this->secure->checkInt($hostID);
1504
        $sHost      = $this->secure->checkStr($info);
1505
 
1506
        $query = "UPDATE ".$this->prefix."rephost SET rhost='".$sHost."' WHERE rhost_id='".$sHostID."'";
1507
        $rq =& $this->db->query($query);
1508
        if (PEAR::isError($this->db)) {
1509
            $result["ERR"] = 1;
1510
            $result["ERRINFO"] = $this->db->getMessage();
1511
        } else {
1512
            $result["ERR"] = 0;
1513
        }
1514
 
1515
        return $result;
1516
    }
1517
 
1518
    /**
1519
     * Вывод формы редактирования/добавления хостов
1520
     *
1521
     * @author Alexander Wolf
1522
     * @category Core
1523
     *
1524
     * @param integer $hostID
1525
     * @param string $info
1526
     * @return string
1527
     */
1528
    public function showHostForm($hostID = 0, $info = "") {
1529
        $sHostID = $this->secure->checkInt($hostID);
1530
        $sInfo = $this->secure->checkStr($info, 1);
1531
        if ($sInfo == "") {
1532
            $sInfo = "Хост репозитория";
1533
        }
1534
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1535
        if ($sHostID != 0) {
1536
            // Режим редактирования
1537
            $query = "SELECT * FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1538
            $rq =& $this->db->query($query);
1539
            $rq->fetchInto($element);
1540
        }
1541
 
1542
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> <input type='text' name='rhost' id='rhost' value='".$this->secure->checkStr($element["rhost"],1)."'></div>\n";
1543
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1544
 
1545
        return $show;
1546
    }
1547
 
1548
    /**
589 alex-w 1549
     * Вывод списка корневых папок
1550
     *
1551
     * @author Alexander Wolf
1552
     * @category Core
1553
     *
1554
     * @param string $name
1555
     * @param string $actor
1556
     * @param string $format
1557
     * @return string
1558
     */
1559
    public function showFoldersList($name, $actor, $format = 'list') {
1560
        switch($format) {
1561
            case 'list':
1562
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1563
                $rq =& $this->db->query($query);
1564
                $show = "<ul>\n";
1565
                while ($rq->fetchInto($element)) {
1566
                    $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";
1567
                }
1568
                $show .= "</ul>";
1569
                break;
1570
            case 'innerhtml':
1571
                $folderID = $this->secure->checkInt($actor);
1572
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1573
                $rq =& $this->db->query($query);
1574
                $show = "<select name='".$name."' id='".$name."'>\n";
1575
                while ($rq->fetchInto($element)) {
1576
                    if ($element["rfolder_id"]==$folderID) {
1577
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."' selected>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1578
                    } else {
1579
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."'>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1580
                    }
1581
                }
1582
                $show .= "</select>";
1583
                break;
1584
        }
1585
        return $show;
1586
    }
1587
 
1588
    /**
1589
     * Добавление нового корневого каталога
1590
     *
1591
     * @author Alexander Wolf
1592
     * @category Core
1593
     *
1594
     * @param string $flder
1595
     * @return array
1596
     */
1597
    public function addFolder($folder) {
1598
        $result = array();
1599
        $sFolder = $this->secure->checkStr($folder);
1600
 
1601
        $query = "INSERT INTO ".$this->prefix."repfolder SET rfolder='".$sFolder."'";
1602
        $rq =& $this->db->query($query);
1603
        if (PEAR::isError($this->db)) {
1604
            $result["ERR"] = 1;
1605
            $result["ERRINFO"] = $this->db->getMessage();
1606
        } else {
1607
            $result["ERR"] = 0;
1608
        }
1609
 
1610
        return $result;
1611
    }
1612
 
1613
    /**
1614
     * Удаление информации о корневой папке
1615
     *
1616
     * @author Alexander Wolf
1617
     * @category Core
1618
     *
1619
     * @param integer $folderID
1620
     * @return array
1621
     */
1622
    public function dropFolder($folderID) {
1623
        $result = array();
1624
        $sFolderID    = $this->secure->checkInt($folderID);
1625
 
1626
        // Удаление корневой папки
1627
        $query = "DELETE FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1628
        $rq =& $this->db->query($query);
1629
        if (PEAR::isError($this->db)) {
1630
            $result["ERR"] = 1;
1631
            $result["ERRINFO"] = $this->db->getMessage();
1632
        } else {
1633
            $result["ERR"] = 0;
1634
        }
1635
 
1636
        return $result;
1637
    }
1638
 
1639
    /**
1640
     * Обновление информации о корневой папки
1641
     *
1642
     * @author Alexander Wolf
1643
     * @category Core
1644
     *
1645
     * @param integer $folderID
1646
     * @param string $info
1647
     * @return array
1648
     */
1649
    public function updateFolder($folderID, $info) {
1650
        $result = array();
1651
        $sFolderID    = $this->secure->checkInt($folderID);
1652
        $sFolder      = $this->secure->checkStr($info);
1653
 
1654
        $query = "UPDATE ".$this->prefix."repfolder SET rfolder='".$sFolder."' WHERE rfolder_id='".$sFolderID."'";
1655
        $rq =& $this->db->query($query);
1656
        if (PEAR::isError($this->db)) {
1657
            $result["ERR"] = 1;
1658
            $result["ERRINFO"] = $this->db->getMessage();
1659
        } else {
1660
            $result["ERR"] = 0;
1661
        }
1662
 
1663
        return $result;
1664
    }
1665
 
1666
    /**
1667
     * Вывод формы редактирования/добавления корневых папок
1668
     *
1669
     * @author Alexander Wolf
1670
     * @category Core
1671
     *
1672
     * @param integer $folderID
1673
     * @param string $info
1674
     * @return string
1675
     */
1676
    public function showFolderForm($folderID = 0, $info = "") {
1677
        $sFolderID = $this->secure->checkInt($folderID);
1678
        $sInfo = $this->secure->checkStr($info, 1);
1679
        if ($sInfo == "") {
1680
            $sInfo = "Корневая папка";
1681
        }
1682
        if ($sFolderID != 0) {
1683
            // Режим редактирования
1684
            $query = "SELECT * FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1685
            $rq =& $this->db->query($query);
1686
            $rq->fetchInto($element);
1687
        }
1688
 
1689
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1690
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> <input type='text' name='rfolder' id='rfolder' value='".$this->secure->checkStr($element["rfolder"],1)."'></div>\n";
1691
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1692
 
1693
        return $show;
1694
    }
1695
 
1696
    /**
539 alex-w 1697
     * Показывает список подписей
1698
     *
1699
     * @author Alexander Wolf
1700
     * @category Core
1701
     *
1702
     * @param string $name
1703
     * @param string $actor
596 alex-w 1704
     * @param string $format
539 alex-w 1705
     * @return string
1706
     */
594 alex-w 1707
    public function showSignsList($name, $actor, $format = 'list') {
539 alex-w 1708
        $query = "SELECT * FROM ".$this->prefix."signs";
1709
        $rq =& $this->db->query($query);
594 alex-w 1710
        switch ($format) {
1711
            case 'list':
1712
                $show = "<ul>\n";
1713
                while ($rq->fetchInto($element)) {
1714
                    $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";
1715
                }
1716
                $show .= "</ul>";
1717
                break;
1718
            case 'innerhtml':
1719
                $signID = $this->secure->checkInt($actor);
1720
                $show  = "<select name='".$name."' id='".$name."'>\n";
1721
                $show .= "<option value='0'>Подписи нет</option>\n";
1722
                while ($rq->fetchInto($element)) {
1723
                    if ($element["sign_id"]==$signID) {
1724
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."' selected>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1725
                    } else {
1726
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."'>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1727
                    }
1728
                }
1729
                $show .= "</select>\n";
1730
                break;
539 alex-w 1731
        }
1732
 
1733
        return $show;
1734
    }
1735
 
1736
    /**
1737
     * Вывод формы редактирования/добавления подписей
1738
     *
1739
     * @author Alexander Wolf
1740
     * @category Core
1741
     *
1742
     * @param integer $sectionID
1743
     * @param string $info
1744
     * @return string
1745
     */
1746
    public function showSignsForm($signID = 0, $info = "") {
1747
        $sSignID = $this->secure->checkInt($signID);
1748
        $sInfo = $this->secure->checkStr($info, 1);
1749
        if ($sInfo == "") {
1750
            $sInfo = "Подписи";
1751
        }
1752
        if ($sSignID != 0) {
1753
            // Режим редактирования
1754
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1755
            $rq =& $this->db->query($query);
1756
            $rq->fetchInto($element);
1757
        }
1758
 
1759
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1760
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
1761
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
1762
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1763
 
1764
        return $show;
1765
    }
1766
 
1767
    /**
1768
     * Обновление информации о секции
1769
     *
1770
     * @author Alexander Wolf
1771
     * @category Core
1772
     *
1773
     * @param integer $sectionID
1774
     * @param string $sname
1775
     * @param string $sinfo
1776
     * @return array
1777
     */
1778
    public function updateSign($signID, $sname, $sinfo = "") {
1779
        $result = array();
1780
        $sSignID    = $this->secure->checkInt($signID);
579 alex-w 1781
        $sSName     = $this->secure->checkStr($sname);
1782
        $sSInfo     = $this->secure->checkStr($sinfo);
539 alex-w 1783
 
1784
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
1785
        $rq =& $this->db->query($query);
1786
        if (PEAR::isError($this->db)) {
1787
            $result["ERR"] = 1;
1788
            $result["ERRINFO"] = $this->db->getMessage();
1789
        } else {
1790
            $result["ERR"] = 0;
1791
        }
1792
 
1793
        return $result;
1794
    }
1795
 
1796
    /**
1797
     * Удаление информации о подписи
1798
     *
1799
     * @author Alexander Wolf
1800
     * @category Core
1801
     *
1802
     * @param integer $sectionID
1803
     * @return array
1804
     */
540 alex-w 1805
    public function dropSign($signID) {
539 alex-w 1806
        $result = array();
1807
        $sSignID    = $this->secure->checkInt($signID);
1808
 
1809
        // Удаление подписи
1810
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1811
        $rq =& $this->db->query($query);
1812
        if (PEAR::isError($this->db)) {
1813
            $result["ERR"] = 1;
1814
            $result["ERRINFO"] = $this->db->getMessage();
1815
        } else {
1816
            $result["ERR"] = 0;
1817
        }
1818
 
1819
        return $result;
1820
    }
1821
 
1822
    /**
540 alex-w 1823
     * Добавление новой подписи
539 alex-w 1824
     *
1825
     * @author Alexander Wolf
1826
     * @category Core
1827
     *
1828
     * @param string $sname
1829
     * @param string $sinfo
1830
     * @return array
1831
     */
540 alex-w 1832
    public function addSign($sname, $sinfo = "") {
539 alex-w 1833
        $result = array();
582 alex-w 1834
        $sSName = $this->secure->checkStr($sname);
1835
        $sSInfo = $this->secure->checkStr($sinfo);
539 alex-w 1836
 
540 alex-w 1837
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 1838
        $rq =& $this->db->query($query);
1839
        if (PEAR::isError($this->db)) {
1840
            $result["ERR"] = 1;
1841
            $result["ERRINFO"] = $this->db->getMessage();
1842
        } else {
1843
            $result["ERR"] = 0;
1844
        }
1845
 
1846
        return $result;
1847
    }
540 alex-w 1848
 
539 alex-w 1849
    /**
463 alex-w 1850
     * Проверка пароля (из формы авторизации)
1851
     *
1852
     * @author Alexander Wolf
1853
     * @category Core
1854
     *
1855
     * @param string $word
1856
     * @return array
1857
     */
368 alex-w 1858
    public function checkSign($word) {
359 alex-w 1859
        $result = array();
1860
 
1861
        $sHash = $this->secure->encryptStr($word);
1862
        $pwd   = $this->getOption("passwd");
1863
        if ($sHash == $pwd["OptValue"]) {
1864
            $result["ERR"] = 0;
1865
            $result["Location"] = "manager.php";
1866
            setcookie($this->cookie, $sHash);
1867
        } else {
1868
            $result["ERR"] = 1;
1869
            $result["ERRINFO"] = "Password not valid";
368 alex-w 1870
            $result["Location"] = "manager.php?error=1";
359 alex-w 1871
        }
1872
 
1873
        return $result;
358 alex-w 1874
    }
357 alex-w 1875
 
463 alex-w 1876
    /**
1877
     * Проверка пароля (из cookies)
1878
     *
1879
     * @author Alexander Wolf
1880
     * @category Core
1881
     *
1882
     * @param string $hash
1883
     * @return array
1884
     */
368 alex-w 1885
    public function checkCookieSign($hash) {
359 alex-w 1886
        $result = array();
1887
 
1888
        $pwd = $this->getOption("passwd");
1889
        if ($hash == $pwd["OptValue"]) {
1890
            $result["ERR"] = 0;
1891
        } else {
1892
            $result["ERR"] = 1;
1893
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 1894
            $result["Location"] = "manager.php";
359 alex-w 1895
        }
1896
 
1897
        return $result;
1898
    }
1899
 
463 alex-w 1900
    /**
1901
     * Форма ввода пароля
1902
     *
1903
     * @author Alexander Wolf
1904
     * @category Core
1905
     *
1906
     * @return string
1907
     */
368 alex-w 1908
    public function showSigninForm() {
425 alex-w 1909
        $show  = "<div id='regform'>";
1910
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 1911
        $show .= "<fieldset><legend>Пароль</legend>\n";
1912
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 1913
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 1914
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 1915
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 1916
 
1917
        return $show;
1918
    }
1919
 
463 alex-w 1920
    /**
1921
     * Обновление пароля
1922
     *
1923
     * @author Alexander Wolf
1924
     * @category Core
1925
     *
1926
     * @param string $word1
1927
     * @param string $word2
1928
     * @return array
1929
     */
368 alex-w 1930
    public function updatePassword($word1, $word2) {
359 alex-w 1931
        $result = array();
1932
 
1933
        if ($word1 == $word2) {
1934
            $sWord = $this->secure->encryptStr($word1);
1935
            $r = $this->setOption("passwd", $sWord);
1936
            $result = $r;
1937
        } else {
1938
            $result["ERR"] = 1;
1939
            $result["ERRINFO"] = "Passwords is mismatch";
1940
        }
1941
 
1942
        return $result;
1943
    }
1944
 
504 alex-w 1945
    /**
509 alex-w 1946
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 1947
     *
1948
     * @author Alexander Wolf
1949
     * @category Core
1950
     *
1951
     * @param string $name
1952
     * @param string $actor
1953
     * @param integer $versionID
1954
     * @return string
1955
     */
511 alex-w 1956
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 1957
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 1958
        $sInfo = $this->secure->checkStr($info, 1);
1959
        if ($sInfo == "") {
1960
            $sInfo = "Версия дистрибутива";
1961
        }
509 alex-w 1962
        if ($sVersionID != 0) {
1963
            // Режим редактирования
556 alex-w 1964
            $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 1965
            $rq =& $this->db->query($query);
1966
            $rq->fetchInto($element);
509 alex-w 1967
        }
1968
 
511 alex-w 1969
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 1970
        if ($sVersionID != 0) {
1971
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
1972
        } else {
1973
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
1974
        }
509 alex-w 1975
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
1976
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
1977
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
1978
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 1979
 
504 alex-w 1980
        return $show;
509 alex-w 1981
    }    
504 alex-w 1982
 
520 alex-w 1983
    /**
1984
     * Парсер схемы адреса репозитория
1985
     * FIXME Возможно не потребуется
1986
     *
1987
     * @author Alexander Wolf
1988
     * @category Core
1989
     *
1990
     * @param string $repstring
1991
     * @return integer
1992
     */
1993
    public function repositoryParser($repstring) {
1994
        $tokens = array();
1995
        $sections = array();
1996
        $tokens = split(" ",$repstring);
1997
 
1998
        if ($tokens[0] == "deb") {
1999
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
2000
            $url = parse_url($tokens[1]);
2001
            $distr  = $tokens[2];
2002
 
2003
            for($i=3;$i<count($tokens);$i++) {
2004
                $sections[] = $tokens[$i];
2005
            }
2006
        } else {
2007
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
2008
            if (stripos($tokens[1],"]")!=0) {
2009
                $sign = $tokens[1];
2010
                $url = parse_url($tokens[2]);
2011
                $base = $tokens[3];
2012
                $repname = $tokens[4];
2013
            } else {
2014
                $url = parse_url($tokens[1]);
2015
                $base = $tokens[2];
2016
                $repname = $tokens[3];
2017
            }
2018
        }
2019
 
2020
        $proto      = $url["scheme"]."://";
2021
        $addr       = $url["host"];
2022
        if ($url["port"]!="") {
2023
            $addr .= ":".$url["port"];
2024
        }
2025
        $path       = $url["path"];
2026
 
2027
        return 0;
2028
    }
2029
 
539 alex-w 2030
    /**
2031
     * Выгрузка картинок логотипов дистрибутивов
2032
     *
2033
     * @author Alexander Wolf
2034
     * @category Core
2035
     *
2036
     * @param string $path
2037
     * @param string $dist
2038
     * @param array $datafile
2039
     * @return integer
2040
     */
535 alex-w 2041
    public function uploadPicture($path, $dist, $datafile) {
2042
        $folder   = $path.$dist."-orig.png";
2043
        $folderN  = $path.$dist.".png";
2044
        $folderEM = $path.$dist."-em.png";
2045
 
2046
        $distlogo = 0;
2047
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
2048
            chmod($folder, 0644);
2049
            list($width, $height) = GetImageSize($folder);
2050
            $percent = 32/$height;
2051
            $newwidth = $width * $percent;
2052
            $newheight = $height * $percent;
2053
 
2054
            $output = ImageCreateTrueColor($newwidth, $newheight);
2055
            $source = ImageCreateFromPNG($folder);
2056
 
2057
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
2058
            ImagePNG($output, $folderEM);
2059
 
2060
            $percent = 15/$height;
2061
            $newwidth = $width * $percent;
2062
            $newheight = $height * $percent;
2063
 
2064
            $output = ImageCreateTrueColor($newwidth, $newheight);
2065
 
2066
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
2067
            ImagePNG($output, $folderN);
2068
 
2069
            unlink($folder);
2070
            $distlogo = 1;
2071
        }
2072
        return $distlogo;
2073
    }
547 alex-w 2074
 
2075
    /**
2076
     * Показ списка репозиториев
2077
     *
2078
     * @author Alexander Wolf
2079
     * @category Core
2080
     *
2081
     * @param string $name
2082
     * @param string $actor
2083
     * @param string $format
2084
     * @return string
2085
     */
548 alex-w 2086
    public function showRepositoriesList($name, $actor, $format = 'list') {
643 alex-w 2087
        $query  = "SELECT r.*,rt.*,v.version_id,CONCAT(d.distname,' ',v.version,' &#8220;',v.vname,'&#8221;') AS fullname FROM ".$this->prefix."repository r ";
548 alex-w 2088
        $query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
629 alex-w 2089
        $query .= "JOIN ".$this->prefix."version v ON v.version_id=r.version ";
641 alex-w 2090
        $query .= "JOIN ".$this->prefix."distribution d ON d.dist_id=v.dist_id ";
629 alex-w 2091
        $query .= "ORDER BY v.version_id,r.rep_id ASC";
548 alex-w 2092
        $rq =& $this->db->query($query);
639 alex-w 2093
        $show = "<ul><li class='nomarker'></li>";
630 alex-w 2094
        $splitter = 0;
548 alex-w 2095
        while ($rq->fetchInto($element)) {
630 alex-w 2096
            if ($splitter != $this->secure->checkInt($element["version_id"])) {
2097
                $splitter = $this->secure->checkInt($element["version_id"]);
645 alex-w 2098
                $show .= "</ul><ul><li class='nomarker'><strong>Репозитории для ".$this->secure->checkStr($element["fullname"],1)."</strong></li>";
630 alex-w 2099
            }
634 alex-w 2100
            $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)." (<em>".$this->secure->checkStr($element["rtype"],1)."</em>)</li>\n";
548 alex-w 2101
        }
2102
        $show .= "</ul>";
547 alex-w 2103
        return $show;
2104
    }
2105
 
2106
    /**
558 alex-w 2107
     * Вывод списка типов репозиториев
2108
     *
2109
     * @author Alexander Wolf
2110
     * @category Core
2111
     *
2112
     * @param integer $reptype
2113
     * @param string $name
2114
     * @return string
2115
     */
2116
    public function showRepType($reptype = 0, $name = "") {
2117
        $sRT = $this->secure->checkInt($reptype);
2118
        $sNM = $this->secure->checkStr($name,1);
559 alex-w 2119
        $query = "SELECT * FROM ".$this->prefix."rtype";
558 alex-w 2120
        $rq =& $this->db->query($query);
2121
        $show = "<select name='".$sNM."' id='".$sNM."'>\n";
2122
        while ($rq->fetchInto($element)) {
2123
            if ($element["rtype_id"]==$sRT) {
2124
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."' selected>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
2125
            } else {
2126
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."'>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
2127
            }
2128
        }
2129
        $show .= "</select>";
2130
 
2131
        return $show;
2132
    }
2133
 
623 alex-w 2134
    /**
2135
     * Вывод списка версий дистрибутивов
2136
     *
2137
     * @author Alexander Wolf
2138
     * @category Core
2139
     *
2140
     * @param string $name
2141
     * @param integer $versionID
2142
     * @return string
2143
     */
591 alex-w 2144
    public function showVDList($name, $versionID = 0) {
592 alex-w 2145
        $query  = "SELECT v.version_id, CONCAT(d.distname, ' ', v.version, ' ', v.vname) AS fullname FROM ".$this->prefix."version v ";
591 alex-w 2146
        $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id";
2147
        $rq =& $this->db->query($query);
2148
        $show = "<select name='".$name."' id='".$name."'>\n";
2149
        while ($rq->fetchInto($element)) {
592 alex-w 2150
            if ($element["version_id"]==$versionID) {
2151
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."' selected>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
2152
            } else {
2153
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
2154
            }
591 alex-w 2155
        }
2156
        $show .= "</select>";
2157
        return $show;
2158
    }
2159
 
558 alex-w 2160
    /**
547 alex-w 2161
     * Форма создания/редактирвоания репозиториев
2162
     *
2163
     * @author Alexander Wolf
2164
     * @category Core
2165
     *
2166
     * @param integer $repID
2167
     * @param string $info
2168
     * @param string $reptype
2169
     * @return string
2170
     */
594 alex-w 2171
    public function showRepositoriesForm($repID = 0, $info = "") {
556 alex-w 2172
        $sRepID = $this->secure->checkInt($repID);
594 alex-w 2173
        $sInfo  = $this->secure->checkStr($info, 1);        
556 alex-w 2174
        if ($sInfo == "") {
2175
            $sInfo = "Репозиторий";
2176
        }
2177
        if ($sRepID != 0) {
2178
            // Режим редактирования
591 alex-w 2179
            $query  = "SELECT r.*,v.*,d.dist_id,dt.type FROM ".$this->prefix."repository r ";
556 alex-w 2180
            $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
2181
            $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ";
2182
            $query .= "JOIN ".$this->prefix."dtype dt ON d.disttype=dt.type_id ";
2183
            $query .= "WHERE r.rep_id='".$sRepID."'";
2184
            $rq =& $this->db->query($query);
594 alex-w 2185
            $rq->fetchInto($element);            
556 alex-w 2186
        }
2187
 
594 alex-w 2188
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";        
609 alex-w 2189
        $show .= "<div class='inputbox'><label for='rdist'>Дистрибутив:</label> ".$this->showVDList("rdist",$this->secure->checkInt($element["version_id"]),"innerhtml")."</div>\n";
626 alex-w 2190
        $show .= "<div class='inputbox'><label for='rname'>Название репозитория:</label> <input type='text' name='rname' value=\"".$this->secure->checkStr($element["repname"],1)."\"></div>\n";
2191
        $show .= "<div class='inputbox'><label for='rinfo'>Описание репозитория:</label> <input type='text' name='rinfo' value=\"".$this->secure->checkStr($element["repinfo"],1)."\"></div>\n";
2192
        $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 2193
        $show .= "<div class='inputbox'><label for='rproto'>Протокол доступа:</label> ".$this->showProtoList("rproto",$this->secure->checkInt($element["proto_id"]),"innerhtml")."</div>\n";
588 alex-w 2194
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> ".$this->showHostsList("rhost",$this->secure->checkInt($element["rhost_id"]),"innerhtml")."</div>\n";
604 alex-w 2195
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> ".$this->showFoldersList("rfolder",$this->secure->checkInt($element["rfolder_id"]),"innerhtml")."</div>\n";
558 alex-w 2196
        $show .= "<div class='inputbox'><label for='rtype'>Тип репозитория:</label> ".$this->showRepType($this->secure->checkInt($element["rtype_id"]), "rtype")."</div>\n";
564 alex-w 2197
        $show .= "<div class='inputbox'><label for='rsects'>Секции репозитория:</label> <div class='formwrapper'>".$this->showSectionsList("rsects",$sRepID,"innerhtml")."</div></div>\n";
569 alex-w 2198
        $show .= "<div class='inputbox'><label for='rarchs'>Архитектуры:</label> <div class='formwrapper'>".$this->showArchList("rarchs",$sRepID,"innerhtml")."</div></div>\n";
613 alex-w 2199
        $show .= "<div class='inputbox'><label for='rscheme'>Схема репозитория:</label> ".$this->showSchemeList("rscheme",$this->secure->checkInt($element["scheme_id"]),"innerhtml")."</div>\n";
595 alex-w 2200
        $show .= "<div class='inputbox'><label for='rsign'>Подпись репозитория:</label> ".$this->showSignsList("rsign",$this->secure->checkInt($element["sign_id"]),"innerhtml")."</div>\n";
556 alex-w 2201
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
593 alex-w 2202
 
547 alex-w 2203
        return $show;
2204
    }
598 alex-w 2205
 
2206
    /**
2207
     * Добавление нового репозитория
2208
     *
2209
     * @author Alexander Wolf
2210
     * @category Core
2211
     *
2212
     * @param integer $verionID
2213
     * @param string $rname
2214
     * @param string $rinfo
2215
     * @param string $rkey
2216
     * @param integer $proto
2217
     * @param integer $rhost
2218
     * @param integer $rfolder
2219
     * @param integer $rtype
2220
     * @param array $sections
2221
     * @param array $arch
2222
     * @param integer $scheme
2223
     * @param integer $sign
2224
     * @return array
2225
     */
612 alex-w 2226
    public function addRepository($verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
598 alex-w 2227
        $result = array();
2228
        $sVersionID     = $this->secure->checkInt($verionID);
2229
        $sRName         = $this->secure->checkStr($rname);
2230
        $sRInfo         = $this->secure->checkStr($rinfo);
2231
        $sRKey          = $this->secure->checkStr($rkey);
2232
        $sProto         = $this->secure->checkInt($proto);
2233
        $sRHost         = $this->secure->checkInt($rhost);
2234
        $sRFolder       = $this->secure->checkInt($rfolder);
2235
        $sRType         = $this->secure->checkInt($rtype);
2236
        $sRScheme       = $this->secure->checkInt($scheme);
2237
        $sRSign         = $this->secure->checkInt($sign);
2238
 
602 alex-w 2239
        $query = "INSERT INTO ".$this->prefix."repository SET proto_id='".$sProto."', rhost_id='".$sRHost."', rfolder_id='".$sRFolder."', version='".$sVersionID."', rtype_id='".$sRType."', scheme_id='".$sRScheme."', sign_id='".$sRSign."', repname='".$sRName."', repinfo='".$sRInfo."', repkey='".$sRKey."'";
598 alex-w 2240
        $rq =& $this->db->query($query);
2241
 
2242
        $query = "SELECT rep_id FROM ".$this->prefix."repository ORDER BY rep_id DESC LIMIT 0, 1";
2243
        $rq =& $this->db->query($query);
2244
        $rq->fetchInto($repository);
2245
 
2246
        for($i=0;$i<count($sections);$i++) {
2247
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$repository["rep_id"]."', sect_id='".$sections[$i]."'";
2248
            $rq =& $this->db->query($query);
2249
        }
2250
 
2251
        for($i=0;$i<count($arch);$i++) {
2252
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$repository["rep_id"]."', arch_id='".$arch[$i]."'";
2253
            $rq =& $this->db->query($query);
2254
        }
2255
 
2256
        if (PEAR::isError($this->db)) {
2257
            $result["ERR"] = 1;
2258
            $result["ERRINFO"] = $this->db->getMessage();
2259
        } else {
2260
            $result["ERR"] = 0;
2261
        }
2262
 
2263
        return $result;
2264
    }
618 alex-w 2265
 
2266
    /**
2267
     * Обновление информации о репозитории
2268
     *
2269
     * @author Alexander Wolf
2270
     * @category Core
2271
     *
2272
     * @param integer $repID
2273
     * @param integer $verionID
2274
     * @param string $rname
2275
     * @param string $rinfo
2276
     * @param string $rkey
2277
     * @param integer $proto
2278
     * @param integer $rhost
2279
     * @param integer $rfolder
2280
     * @param integer $rtype
2281
     * @param array $sections
2282
     * @param array $arch
2283
     * @param integer $scheme
2284
     * @param integer $sign
2285
     * @return array
2286
     */
2287
    public function updateRepository($repID, $verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
2288
        $result = array();
2289
        $sRepID         = $this->secure->checkInt($repID);
2290
        $sVersionID     = $this->secure->checkInt($verionID);
2291
        $sRName         = $this->secure->checkStr($rname);
2292
        $sRInfo         = $this->secure->checkStr($rinfo);
2293
        $sRKey          = $this->secure->checkStr($rkey);
2294
        $sProto         = $this->secure->checkInt($proto);
2295
        $sRHost         = $this->secure->checkInt($rhost);
2296
        $sRFolder       = $this->secure->checkInt($rfolder);
2297
        $sRType         = $this->secure->checkInt($rtype);
2298
        $sRScheme       = $this->secure->checkInt($scheme);
2299
        $sRSign         = $this->secure->checkInt($sign);
2300
 
2301
        $query = "UPDATE ".$this->prefix."repository SET proto_id='".$sProto."', rhost_id='".$sRHost."', rfolder_id='".$sRFolder."', version='".$sVersionID."', rtype_id='".$sRType."', scheme_id='".$sRScheme."', sign_id='".$sRSign."', repname='".$sRName."', repinfo='".$sRInfo."', repkey='".$sRKey."' WHERE rep_id='".$sRepID."'";
2302
        $rq =& $this->db->query($query);
2303
 
2304
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2305
        $rq =& $this->db->query($query);
2306
        for($i=0;$i<count($sections);$i++) {
2307
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$sRepID."', sect_id='".$sections[$i]."'";
2308
            $rq =& $this->db->query($query);
2309
        }
2310
 
2311
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2312
        $rq =& $this->db->query($query);
2313
        for($i=0;$i<count($arch);$i++) {
2314
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$sRepID."', arch_id='".$arch[$i]."'";
2315
            $rq =& $this->db->query($query);
2316
        }
2317
 
2318
        if (PEAR::isError($this->db)) {
2319
            $result["ERR"] = 1;
2320
            $result["ERRINFO"] = $this->db->getMessage();
2321
        } else {
2322
            $result["ERR"] = 0;
2323
        }
2324
 
2325
        return $result;
2326
    }
2327
 
2328
    /**
2329
     * Удаление информации о репозитории
2330
     *
2331
     * @author Alexander Wolf
2332
     * @category Core
2333
     *
2334
     * @param integer $repID
2335
     * @return array
2336
     */
2337
    public function dropRepository($repID) {
2338
        $result = array();
2339
        $sRepID         = $this->secure->checkInt($repID);
2340
 
2341
        // Удаление репозитория
2342
        $query = "DELETE FROM ".$this->prefix."repository WHERE rep_id='".$sRepID."'";
2343
        $rq =& $this->db->query($query);
2344
        if (PEAR::isError($this->db)) {
2345
            $result["ERR"] = 1;
2346
            $result["ERRINFO"] = $this->db->getMessage();
2347
        } else {
2348
            $result["ERR"] = 0;
2349
        }
2350
 
2351
        // Удаление секций репозитория
2352
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2353
        $rq =& $this->db->query($query);
2354
        if (PEAR::isError($this->db)) {
2355
            $result["ERR"] = 1;
2356
            $result["ERRINFO"] = $this->db->getMessage();
2357
        } else {
2358
            $result["ERR"] = 0;
2359
        }
2360
 
2361
        // Удаление архитектур репозитория
2362
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2363
        $rq =& $this->db->query($query);
2364
        if (PEAR::isError($this->db)) {
2365
            $result["ERR"] = 1;
2366
            $result["ERRINFO"] = $this->db->getMessage();
2367
        } else {
2368
            $result["ERR"] = 0;
2369
        }
2370
 
2371
        return $result;
2372
    }
560 alex-w 2373
 
304 alex-w 2374
}
2375
 
356 alex-w 2376
?>