Хранилища Subversion ant

Редакция

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