View | Details | Raw Unified | Return to bug 7977
Collapse All | Expand All

(-)a/C4/Koha.pm (-1 / +79 lines)
Lines 22-31 package C4::Koha; Link Here
22
22
23
use strict;
23
use strict;
24
#use warnings; FIXME - Bug 2505
24
#use warnings; FIXME - Bug 2505
25
25
use C4::Context;
26
use C4::Context;
27
26
use Memoize;
28
use Memoize;
29
use DateTime;
30
use DateTime::Format::MySQL;
31
use autouse 'Data::Dumper' => qw(Dumper);
27
32
28
use vars qw($VERSION @ISA @EXPORT $DEBUG);
33
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
29
34
30
BEGIN {
35
BEGIN {
31
	$VERSION = 3.01;
36
	$VERSION = 3.01;
Lines 67-72 BEGIN { Link Here
67
		$DEBUG
72
		$DEBUG
68
	);
73
	);
69
	$DEBUG = 0;
74
	$DEBUG = 0;
75
@EXPORT_OK = qw( GetDailyQuote );
70
}
76
}
71
77
72
# expensive functions
78
# expensive functions
Lines 1301-1306 sub GetNormalizedOCLCNumber { Link Here
1301
    }
1307
    }
1302
}
1308
}
1303
1309
1310
=head2 GetDailyQuote($opts)
1311
1312
Takes a hashref of options
1313
1314
Currently supported options are:
1315
1316
'id'        An exact quote id
1317
'random'    Select a random quote
1318
noop        When no option is passed in, this sub will return the quote timestamped for the current day
1319
1320
The function returns an anonymous hash following this format:
1321
1322
        {
1323
          'source' => 'source-of-quote',
1324
          'timestamp' => 'timestamp-value',
1325
          'text' => 'text-of-quote',
1326
          'id' => 'quote-id'
1327
        };
1328
1329
=cut
1330
1331
# This is definitely a candidate for some sort of caching once we finally settle caching/persistence issues...
1332
# at least for default option
1333
1334
sub GetDailyQuote {
1335
    my %opts = @_;
1336
    my $dbh = C4::Context->dbh;
1337
    my $query = '';
1338
    my $sth = undef;
1339
    my $quote = undef;
1340
    if ($opts{'id'}) {
1341
        $query = 'SELECT * FROM quotes WHERE id = ?';
1342
        $sth = $dbh->prepare($query);
1343
        $sth->execute($opts{'id'});
1344
        $quote = $sth->fetchrow_hashref();
1345
    }
1346
    elsif ($opts{'random'}) {
1347
        # Fall through... we also return a random quote as a catch-all if all else fails
1348
    }
1349
    else {
1350
        $query = 'SELECT * FROM quotes WHERE timestamp LIKE CONCAT(CURRENT_DATE,\'%\') ORDER BY timestamp LIMIT 0,1';
1351
        $sth = $dbh->prepare($query);
1352
        $sth->execute();
1353
        $quote = $sth->fetchrow_hashref();
1354
    }
1355
    unless ($quote) {        # if there are not matches, choose a random quote
1356
        # get a list of all available quote ids
1357
        $sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;');
1358
        $sth->execute;
1359
        my $range = ($sth->fetchrow_array)[0];
1360
        if ($range > 1) {
1361
            # chose a random id within that range if there is more than one quote
1362
            my $id = int(rand($range));
1363
            # grab it
1364
            $query = 'SELECT * FROM quotes WHERE id = ?;';
1365
            $sth = C4::Context->dbh->prepare($query);
1366
            $sth->execute($id);
1367
        }
1368
        else {
1369
            $query = 'SELECT * FROM quotes;';
1370
            $sth = C4::Context->dbh->prepare($query);
1371
            $sth->execute();
1372
        }
1373
        $quote = $sth->fetchrow_hashref();
1374
        # update the timestamp for that quote
1375
        $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
1376
        $sth = C4::Context->dbh->prepare($query);
1377
        $sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $quote->{'id'});
1378
    }
1379
    return $quote;
1380
}
1381
1304
sub _normalize_match_point {
1382
sub _normalize_match_point {
1305
    my $match_point = shift;
1383
    my $match_point = shift;
1306
    (my $normalized_match_point) = $match_point =~ /([\d-]*[X]*)/;
1384
    (my $normalized_match_point) = $match_point =~ /([\d-]*[X]*)/;
(-)a/installer/data/mysql/de-DE/mandatory/userpermissions.sql (+1 lines)
Lines 22-27 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
22
   (13, 'moderate_comments', 'Benutzerkommentare moderieren'),
22
   (13, 'moderate_comments', 'Benutzerkommentare moderieren'),
23
   (13, 'edit_notices', 'Benachrichtigungen verwalten'),
23
   (13, 'edit_notices', 'Benachrichtigungen verwalten'),
24
   (13, 'edit_notice_status_triggers', 'Mahntrigger für überfällige Medien verwalten'),
24
   (13, 'edit_notice_status_triggers', 'Mahntrigger für überfällige Medien verwalten'),
25
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
25
   (13, 'view_system_logs', 'Logs durchsuchen/einsehen'),
26
   (13, 'view_system_logs', 'Logs durchsuchen/einsehen'),
26
   (13, 'inventory', 'Inventur durchführen'),
27
   (13, 'inventory', 'Inventur durchführen'),
27
   (13, 'stage_marc_import', 'MARC-Datensätze zwischenspeichern'),
28
   (13, 'stage_marc_import', 'MARC-Datensätze zwischenspeichern'),
(-)a/installer/data/mysql/en/mandatory/userpermissions.sql (+1 lines)
Lines 22-27 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
22
   (13, 'moderate_comments', 'Moderate patron comments'),
22
   (13, 'moderate_comments', 'Moderate patron comments'),
23
   (13, 'edit_notices', 'Define notices'),
23
   (13, 'edit_notices', 'Define notices'),
24
   (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
24
   (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
25
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
25
   (13, 'view_system_logs', 'Browse the system logs'),
26
   (13, 'view_system_logs', 'Browse the system logs'),
26
   (13, 'inventory', 'Perform inventory (stocktaking) of your catalog'),
27
   (13, 'inventory', 'Perform inventory (stocktaking) of your catalog'),
27
   (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
28
   (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
(-)a/installer/data/mysql/en/optional/sample_quotes.sql (+34 lines)
Line 0 Link Here
1
/*!40000 ALTER TABLE `quotes` DISABLE KEYS */;
2
INSERT INTO `quotes` VALUES
3
(1,'George Washington','To be prepared for war is one of the most effectual means of preserving peace.','0000-00-00 00:00:00'),
4
(2,'Thomas Jefferson','When angry, count ten, before you speak; if very angry, an hundred.','0000-00-00 00:00:00'),
5
(3,'Abraham Lincoln','Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.','2012-04-12 20:30:59'),
6
(4,'Abraham Lincoln','I have always found that mercy bears richer fruits than strict justice.','0000-00-00 00:00:00'),
7
(5,'Andrew Johnson','I feel incompetent to perform duties...which have been so unexpectedly thrown upon me.','0000-00-00 00:00:00'),
8
(6,'Rutherford B. Hayes','He serves his party best who serves his country best.','0000-00-00 00:00:00'),
9
(7,'Theodore Roosevelt','No President has ever enjoyed himself as much as I?','0000-00-00 00:00:00'),
10
(8,'Theodore Roosevelt','Speak softly and carry a big stick.','0000-00-00 00:00:00'),
11
(9,'William H. Taft','I have come to the conclusion that the major part of the president is to increase the gate receipts of expositions and fairs and bring tourists to town.','0000-00-00 00:00:00'),
12
(11,'Woodrow Wilson','You cannot become thorough Americans if you think of yourselves in groups. America does not consist of groups. A man who thinks of himself as belonging to a particular national group in America has not yet become an American.','0000-00-00 00:00:00'),
13
(12,'Calvin Coolidge','If you don\'t say anything, you won\'t be called on to repeat it.','0000-00-00 00:00:00'),
14
(13,'Calvin Coolidge','Four fifths of all our troubles in this life would disappear if we would only sit down and keep still.','0000-00-00 00:00:00'),
15
(14,'Herbert Hoover','The slogan of progress is changing from the full dinner pail to the full garage.','0000-00-00 00:00:00'),
16
(15,'Franklin D. Roosevelt','Let me assert my firm belief that the only thing we have to fear is fear itself.','0000-00-00 00:00:00'),
17
(16,'Harry S. Truman','If you can\'t stand the heat, get out of the kitchen.','0000-00-00 00:00:00'),
18
(17,'Harry S. Truman','The atom bomb was no great decision. It was merely another powerful weapon in the arsenal of righteousness.','0000-00-00 00:00:00'),
19
(18,'Harry S. Truman','The buck stops here.','0000-00-00 00:00:00'),
20
(19,'Dwight D. Eisenhower','History does not long entrust the care of freedom to the weak or the timid.','0000-00-00 00:00:00'),
21
(20,'John F. Kennedy','My fellow Americans, ask not what your country can do for you; ask what you can do for your country.','0000-00-00 00:00:00'),
22
(22,'John F. Kennedy','I do not think it altogether inappropriate to introduce myself to this audience. I am the man who accompanied Jacqueline Kennedy to Paris, and I have enjoyed it.','0000-00-00 00:00:00'),
23
(23,'Lyndon B. Johnson','The Great Society is a place where every child can find knowledge to enrich his mind and to enlarge his talents. It is a place where the city of man serves not only the needs of the body and the demands of commerce but the desire for beauty and the hunger for community. It is a place where men are more concerned with the quality of their goals than the quantity of their goods.','0000-00-00 00:00:00'),
24
(24,'Richard Nixon','People have got to know whether or not their president is a crook. Well, I\'m not a crook.','0000-00-00 00:00:00'),
25
(25,'Richard Nixon','When the President does it, that means that it is not illegal.','0000-00-00 00:00:00'),
26
(26,'Gerald R. Ford','Our Long national nightmare is over.','2012-04-18 19:42:14'),
27
(27,'Gerald R. Ford','Our constitution works. Our great republic is a government of laws, not of men.','0000-00-00 00:00:00'),
28
(28,'Jimmy Carter','A strong nation, like a strong person, can afford to be gentle, firm, thoughtful, and restrained. It can afford to extend a helping hand to others. It\'s a weak nation, like a weak person, that must behave with bluster and boasting and rashness and other signs of insecurity.','0000-00-00 00:00:00'),
29
(30,'Ronald Reagan','It is not my intention to do away with government. It is rather to make it work -work with us, not over us; stand by our side, not ride on our back. Government can and must provide opportunity, not smother it; foster productivity, not stifle it. This Administration\'s objective will be a healthy, vigorous, growing economy.','0000-00-00 00:00:00'),
30
(31,'Ronald Reagan','Each generation goes further than the generation preceding it because it stands on the shoulders of that generation. You will have opportunities beyond anything we\'ve ever known.','0000-00-00 00:00:00'),
31
(32,'George H. W. Bush ','We have ...drawn a line in the sand.','0000-00-00 00:00:00'),
32
(33,'George W. Bush','If America shows weakness and uncertainty, the world will drift toward tragedy. That will not happen on my watch.','0000-00-00 00:00:00'),
33
(34,'George W. Bush','Every nation in every region now has a decision to make. Either you are with us, or you are with the terrorists.','0000-00-00 00:00:00');
34
/*!40000 ALTER TABLE `quotes` ENABLE KEYS */;
(-)a/installer/data/mysql/en/optional/sample_quotes.txt (+1 lines)
Line 0 Link Here
1
Sample Quotes
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/userpermissions.sql (+1 lines)
Lines 12-17 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
12
   (13, 'moderate_comments', 'Modérer les commentaires des adhérents'),
12
   (13, 'moderate_comments', 'Modérer les commentaires des adhérents'),
13
   (13, 'edit_notices', 'Définir les notifications'),
13
   (13, 'edit_notices', 'Définir les notifications'),
14
   (13, 'edit_notice_status_triggers', 'Définir les déclencheurs de notification de retard'),
14
   (13, 'edit_notice_status_triggers', 'Définir les déclencheurs de notification de retard'),
15
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
15
   (13, 'view_system_logs', 'Parcourir les journaux de l''activité du système'),
16
   (13, 'view_system_logs', 'Parcourir les journaux de l''activité du système'),
16
   (13, 'inventory', 'Réaliser les tâches de récolement'),
17
   (13, 'inventory', 'Réaliser les tâches de récolement'),
17
   (13, 'stage_marc_import', 'Importer des notices MARC dans le réservoir'),
18
   (13, 'stage_marc_import', 'Importer des notices MARC dans le réservoir'),
(-)a/installer/data/mysql/it-IT/necessari/userpermissions.sql (+1 lines)
Lines 24-29 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
24
   (13, 'moderate_comments', 'Modera i commenti degli utenti'),
24
   (13, 'moderate_comments', 'Modera i commenti degli utenti'),
25
   (13, 'edit_notices', 'Definisci le notifiche'),
25
   (13, 'edit_notices', 'Definisci le notifiche'),
26
   (13, 'edit_notice_status_triggers', 'Imposta il messaggio o lo stato delle notifiche per le copie in ritardo'),
26
   (13, 'edit_notice_status_triggers', 'Imposta il messaggio o lo stato delle notifiche per le copie in ritardo'),
27
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
27
   (13, 'view_system_logs', 'Scorri i log di sistema'),
28
   (13, 'view_system_logs', 'Scorri i log di sistema'),
28
   (13, 'inventory', 'Lavora sugli inventari (stocktaking) del tuo catalogo'),
29
   (13, 'inventory', 'Lavora sugli inventari (stocktaking) del tuo catalogo'),
29
   (13, 'stage_marc_import', 'Opera sui Record MARC presenti nella zona di lavoro'),
30
   (13, 'stage_marc_import', 'Opera sui Record MARC presenti nella zona di lavoro'),
(-)a/installer/data/mysql/kohastructure.sql (+13 lines)
Lines 2829-2834 CREATE TABLE ratings ( Link Here
2829
    CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2829
    CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2830
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2830
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2831
2831
2832
--
2833
-- Table structure for table `quotes`
2834
--
2835
2836
DROP TABLE IF EXISTS quotes;
2837
CREATE TABLE `quotes` (
2838
  `id` int(11) NOT NULL AUTO_INCREMENT,
2839
  `source` varchar(45) DEFAULT NULL,
2840
  `text` mediumtext NOT NULL,
2841
  `timestamp` datetime NOT NULL,
2842
  PRIMARY KEY (`id`)
2843
) ENGINE=InnoDB DEFAULT CHARSET=utf8
2844
2832
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2845
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2833
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2846
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2834
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2847
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/nb-NO/1-Obligatorisk/userpermissions.sql (+1 lines)
Lines 43-48 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
43
   (13, 'moderate_comments', 'Behandle kommentarer fra lånere'),
43
   (13, 'moderate_comments', 'Behandle kommentarer fra lånere'),
44
   (13, 'edit_notices', 'Definere meldinger'),
44
   (13, 'edit_notices', 'Definere meldinger'),
45
   (13, 'edit_notice_status_triggers', 'Definere utløsere for meldinger og statusenderinger for for sent leverte dokumenter'),
45
   (13, 'edit_notice_status_triggers', 'Definere utløsere for meldinger og statusenderinger for for sent leverte dokumenter'),
46
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
46
   (13, 'view_system_logs', 'Se Koha sine logger'),
47
   (13, 'view_system_logs', 'Se Koha sine logger'),
47
   (13, 'inventory', 'Foreta varetelling'),
48
   (13, 'inventory', 'Foreta varetelling'),
48
   (13, 'stage_marc_import', 'Importere MARC-poster til brønnen'),
49
   (13, 'stage_marc_import', 'Importere MARC-poster til brønnen'),
(-)a/installer/data/mysql/pl-PL/mandatory/userpermissions.sql (+1 lines)
Lines 22-27 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
22
   (13, 'moderate_comments', 'Moderate patron comments'),
22
   (13, 'moderate_comments', 'Moderate patron comments'),
23
   (13, 'edit_notices', 'Define notices'),
23
   (13, 'edit_notices', 'Define notices'),
24
   (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
24
   (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
25
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
25
   (13, 'view_system_logs', 'Przeglądanie logów systemowych'),
26
   (13, 'view_system_logs', 'Przeglądanie logów systemowych'),
26
   (13, 'inventory', 'Perform inventory (stocktaking) of your catalog'),
27
   (13, 'inventory', 'Perform inventory (stocktaking) of your catalog'),
27
   (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
28
   (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
(-)a/installer/data/mysql/ru-RU/mandatory/permissions_and_user_flags.sql (+1 lines)
Lines 46-51 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
46
   (13, 'moderate_comments',           'Регулировка комментариев от посетителей'),
46
   (13, 'moderate_comments',           'Регулировка комментариев от посетителей'),
47
   (13, 'edit_notices',                'Определение сообщений'),
47
   (13, 'edit_notices',                'Определение сообщений'),
48
   (13, 'edit_notice_status_triggers', 'Установка триггеров сообщений/статусов для просроченных экземпляров'),
48
   (13, 'edit_notice_status_triggers', 'Установка триггеров сообщений/статусов для просроченных экземпляров'),
49
   (13, 'edit_quotes',                 'Edit quotes for quote-of-the-day feature'),
49
   (13, 'view_system_logs',            'Просмотр протоколов системы'),
50
   (13, 'view_system_logs',            'Просмотр протоколов системы'),
50
   (13, 'inventory',                   'Проведение инвентаризации(анализа) Вашего каталога'),
51
   (13, 'inventory',                   'Проведение инвентаризации(анализа) Вашего каталога'),
51
   (13, 'stage_marc_import',           'Заготовка МАРК-записей в хранилище'),
52
   (13, 'stage_marc_import',           'Заготовка МАРК-записей в хранилище'),
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 95-100 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES Link Here
95
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacPublic',1,'Turn on/off public OPAC',NULL,'YesNo');
95
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacPublic',1,'Turn on/off public OPAC',NULL,'YesNo');
96
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('opacuserjs','','Define custom javascript for inclusion in OPAC','70|10','Textarea');
96
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('opacuserjs','','Define custom javascript for inclusion in OPAC','70|10','Textarea');
97
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('opacuserlogin',1,'Enable or disable display of user login features',NULL,'YesNo');
97
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('opacuserlogin',1,'Enable or disable display of user login features',NULL,'YesNo');
98
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QuoteOfTheDay',0,'Enable or disable display of Quote of the Day on the OPAC home page',NULL,'YesNo');
98
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('patronimages',0,'Enable patron images for the Staff Client',NULL,'YesNo');
99
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('patronimages',0,'Enable patron images for the Staff Client',NULL,'YesNo');
99
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACpatronimages',0,'Enable patron images in the OPAC',NULL,'YesNo');
100
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACpatronimages',0,'Enable patron images in the OPAC',NULL,'YesNo');
100
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('printcirculationslips',1,'If ON, enable printing circulation receipts','','YesNo');
101
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('printcirculationslips',1,'If ON, enable printing circulation receipts','','YesNo');
(-)a/installer/data/mysql/uk-UA/mandatory/permissions_and_user_flags.sql (+1 lines)
Lines 46-51 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
46
   (13, 'moderate_comments',           'Регулювання коментарів від відвідувачів'),
46
   (13, 'moderate_comments',           'Регулювання коментарів від відвідувачів'),
47
   (13, 'edit_notices',                'Визначення повідомлень'),
47
   (13, 'edit_notices',                'Визначення повідомлень'),
48
   (13, 'edit_notice_status_triggers', 'Встановлення тригерів повідомлень/статусів для прострочених примірників'),
48
   (13, 'edit_notice_status_triggers', 'Встановлення тригерів повідомлень/статусів для прострочених примірників'),
49
   (13, 'edit_quotes', 'Edit quotes for quote-of-the-day feature'),
49
   (13, 'view_system_logs',            'Перегляд протоколів системи'),
50
   (13, 'view_system_logs',            'Перегляд протоколів системи'),
50
   (13, 'inventory',                   'Проведення інвентаризації(аналізу) Вашого каталогу'),
51
   (13, 'inventory',                   'Проведення інвентаризації(аналізу) Вашого каталогу'),
51
   (13, 'stage_marc_import',           'Заготівля МАРК-записів у сховище'),
52
   (13, 'stage_marc_import',           'Заготівля МАРК-записів у сховище'),
(-)a/installer/data/mysql/updatedatabase.pl (+23 lines)
Lines 5219-5224 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5219
    SetVersion($DBversion);
5219
    SetVersion($DBversion);
5220
}
5220
}
5221
5221
5222
$DBversion = "3.09.00.XXX";
5223
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5224
    unless (TableExists('quotes')) {
5225
        $dbh->do( qq{
5226
            CREATE TABLE `quotes` (
5227
              `id` int(11) NOT NULL AUTO_INCREMENT,
5228
              `source` varchar(45) DEFAULT NULL,
5229
              `text` mediumtext NOT NULL,
5230
              `timestamp` datetime NOT NULL,
5231
              PRIMARY KEY (`id`)
5232
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8
5233
        });
5234
    }
5235
    $dbh->do( qq{
5236
        INSERT IGNORE INTO permissions VALUES (13, "edit_quotes","Edit quotes for quote-of-the-day feature");
5237
    });
5238
    $dbh->do( qq{
5239
        INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QuoteOfTheDay',0,'Enable or disable display of Quote of the Day on the OPAC home page',NULL,'YesNo');
5240
    });
5241
    print "Upgrade to $DBversion done (Adding Quote of the Day Option.)\n";
5242
    SetVersion($DBversion);
5243
}
5244
5222
=head1 FUNCTIONS
5245
=head1 FUNCTIONS
5223
5246
5224
=head2 TableExists($table)
5247
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/datatables.css (-4 / +19 lines)
Lines 85-109 div.dataTables_paginate { Link Here
85
.paging_full_numbers a.paginate_button.first {
85
.paging_full_numbers a.paginate_button.first {
86
    background-image : url('../../img/first.png');
86
    background-image : url('../../img/first.png');
87
    background-repeat: no-repeat;
87
    background-repeat: no-repeat;
88
    background-position : 2px center;
88
    background-position : 1% center;
89
    padding-left : 2em;
89
    padding-left : 2em;
90
}
90
}
91
.paging_full_numbers a.paginate_button.previous {
91
.paging_full_numbers a.paginate_button.previous {
92
    background-image : url('../../img/prev.png');
92
    background-image : url('../../img/prev.png');
93
    background-repeat: no-repeat;
93
    background-repeat: no-repeat;
94
    background-position : 2px center;
94
    background-position : 1% center;
95
    padding-left : 2em;
95
    padding-left : 2em;
96
}
96
}
97
.paging_full_numbers a.paginate_button.next {
97
.paging_full_numbers a.paginate_button.next {
98
    background-image : url('../../img/next.png');
98
    background-image : url('../../img/next.png');
99
    background-repeat: no-repeat;
99
    background-repeat: no-repeat;
100
    background-position : right center;
100
    background-position : 96% center;
101
    padding-right : 2em;
101
    padding-right : 2em;
102
}
102
}
103
.paging_full_numbers a.paginate_button.last {
103
.paging_full_numbers a.paginate_button.last {
104
    background-image : url('../../img/last.png');
104
    background-image : url('../../img/last.png');
105
    background-repeat: no-repeat;
105
    background-repeat: no-repeat;
106
    background-position : right center;
106
    background-position : 96% center;
107
    border-right : 1px solid #686868;
107
    border-right : 1px solid #686868;
108
    padding-right : 2em;
108
    padding-right : 2em;
109
}
109
}
Lines 175-180 div.dataTables_paginate.paging_four_button { Link Here
175
    cursor: pointer;
175
    cursor: pointer;
176
}
176
}
177
177
178
.dataTables_processing {
179
    background-color: white;
180
    border: 1px solid #DDDDDD;
181
    color: #999999;
182
    font-size: 14px;
183
    height: 30px;
184
    left: 50%;
185
    margin-left: -125px;
186
    margin-top: -15px;
187
    padding: 14px 0 2px;
188
    position: fixed;
189
    text-align: center;
190
    top: 50%;
191
    width: 250px;
192
}
178
193
179
/*
194
/*
180
table.display {
195
table.display {
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+8 lines)
Lines 26-31 a:hover, a:active { Link Here
26
    text-decoration: none;
26
    text-decoration: none;
27
}
27
}
28
28
29
.yui-button {
30
    border-radius: 5px;
31
}
32
33
.yui-button .first-child {
34
    border-radius: 5px;
35
}
36
29
.yui-button,.yui-button a:link,.yui-button a:visited {
37
.yui-button,.yui-button a:link,.yui-button a:visited {
30
	color : #000;
38
	color : #000;
31
}
39
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/quotes-toolbar.inc (+48 lines)
Line 0 Link Here
1
<script type="text/javascript">
2
    //<![CDATA[
3
    // prepare DOM for YUI Toolbar
4
    $(document).ready(function() {
5
        $("#add_quote").empty();
6
        $("#delete_quote").empty();
7
        $("#import_quotes").empty();
8
        yuiToolbar();
9
     });
10
11
    // YUI Toolbar Functions
12
    function yuiToolbar() {
13
14
        new YAHOO.widget.Button({
15
            type: "button",
16
            label: _("Add quote"),
17
            name: "add",
18
            container: "add_quote",
19
            onclick: {fn: fnClickAddRow}
20
        });
21
22
        new YAHOO.widget.Button({
23
            type: "button",
24
            label: _("Delete quote(s)"),
25
            name: "delete",
26
            container: "delete_quote",
27
            onclick: {fn: fnClickDeleteRow}
28
        });
29
30
        new YAHOO.widget.Button({
31
            type: "button",
32
            label: _("Import quotes"),
33
            name: "import",
34
            container: "import_quotes",
35
            onclick: {fn: function (){parent.location="quotes-upload.pl";}}
36
        });
37
    }
38
39
//]]>
40
</script>
41
<div id="toolbar">
42
    <ul class="toolbar">
43
        <li id="add_quote"><a id="add" href="#">Add quote</a></li>
44
        <li id="delete_quote"><a id="delete" href="#">Delete quote(s)</a></li>
45
        <li id="import_quotes"><a id="import" href="#">Import quotes</a></li>
46
        <span class="hint" style="">Click Source or Text field to edit contents. Press &lt;Enter&gt; to save changes.</span>
47
    </ul>
48
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (+3 lines)
Lines 91-94 Link Here
91
    [% IF ( CAN_user_tools_schedule_tasks ) %]
91
    [% IF ( CAN_user_tools_schedule_tasks ) %]
92
	<li><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></li>
92
	<li><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></li>
93
    [% END %]
93
    [% END %]
94
    [% IF ( CAN_user_tools_edit_quotes ) %]
95
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
96
    [% END %]
94
</ul></div></div>
97
</ul></div></div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/dataTables.fnReloadAjax.js (+50 lines)
Line 0 Link Here
1
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
2
{
3
    if ( typeof sNewSource != 'undefined' && sNewSource != null )
4
    {
5
        oSettings.sAjaxSource = sNewSource;
6
    }
7
    this.oApi._fnProcessingDisplay( oSettings, true );
8
    var that = this;
9
    var iStart = oSettings._iDisplayStart;
10
    var aData = [];
11
12
    this.oApi._fnServerParams( oSettings, aData );
13
14
    oSettings.fnServerData( oSettings.sAjaxSource, aData, function(json) {
15
        /* Clear the old information from the table */
16
        that.oApi._fnClearTable( oSettings );
17
18
        /* Got the data - add it to the table */
19
        var aData =  (oSettings.sAjaxDataProp !== "") ?
20
            that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
21
22
        for ( var i=0 ; i<aData.length ; i++ )
23
        {
24
            that.oApi._fnAddData( oSettings, aData[i] );
25
        }
26
27
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
28
        that.fnDraw();
29
30
        if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
31
        {
32
            oSettings._iDisplayStart = iStart;
33
            that.fnDraw( false );
34
        }
35
36
        that.oApi._fnProcessingDisplay( oSettings, false );
37
38
        /* Callback user function - for event handlers etc */
39
        if ( typeof fnCallback == 'function' && fnCallback != null )
40
        {
41
            fnCallback( oSettings );
42
        }
43
    }, oSettings );
44
}
45
46
/* Example call to load a new file */
47
//oTable.fnReloadAjax( 'media/examples_support/json_source2.txt' );
48
49
/* Example call to reload from original file */
50
//oTable.fnReloadAjax();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (-1 / +7 lines)
Lines 330-336 OPAC: Link Here
330
                  yes: Enable
330
                  yes: Enable
331
                  no: Disable
331
                  no: Disable
332
            - browsing and paging search results from the OPAC detail page.
332
            - browsing and paging search results from the OPAC detail page.
333
333
        -
334
            - pref: QuoteOfTheDay
335
              default: 0
336
              choices:
337
                  yes: Enable
338
                  no: Disable
339
            - Quote of the Day display on OPAC home page
334
    Policy:
340
    Policy:
335
        -
341
        -
336
            - pref: singleBranchMode
342
            - pref: singleBranchMode
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt (+205 lines)
Line 0 Link Here
1
    [% INCLUDE 'doc-head-open.inc' %]
2
    <title>Koha &rsaquo; Tools &rsaquo; Quote editor</title>
3
    [% INCLUDE 'doc-head-close.inc' %]
4
    <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
5
    <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
    <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/dataTables.fnReloadAjax.js"></script>
7
    [% INCLUDE 'datatables-strings.inc' %]
8
    </script>
9
    <script type="text/javascript" src="/intranet-tmpl/prog/en/js/datatables.js"></script>
10
    <script type="text/javascript" src="/intranet-tmpl/prog/en/js/jquery.jeditable.mini.js"></script>
11
    <script type="text/javascript">
12
    //<![CDATA[
13
    var oTable; /* oTable needs to be global */
14
    var sEmptyTable = _('No quotes available. Please use the \"Add Quote\" button to add a quote.'); /* override the default message in datatables-strings.inc */
15
    $(document).ready(function() {
16
        /* NOTE: This is an ajax-source datatable and *not* a server-side sourced datatable. */
17
        /* See the datatable docs if you don't understand this difference. */
18
        oTable = $("#quotes_editor").dataTable({
19
                    "bAutoWidth"        : false,
20
                    "bProcessing"       : true,
21
                    "bPaginate"         : true,
22
                    "sPaginationType"   : "full_numbers",
23
                    "sAjaxSource"       : "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
24
                    "aoColumns"         : [
25
                                            { "sWidth": "3%"  },
26
                                            { "sWidth": "11%" },
27
                                            { "sWidth": "75%" },
28
                                            { "sWidth": "11%" },
29
                                          ],
30
                   "oLanguage"          : {
31
                                            "sEmptyTable": sEmptyTable,
32
                                          },
33
                   "fnPreDrawCallback": function(oSettings) {
34
                        return true;
35
                    },
36
                    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
37
                        /* do foo on the current row and its child nodes */
38
                        var noEditFields = [];
39
                        var quoteID = $('td', nRow)[0].innerHTML;
40
                        $(nRow).attr("id", quoteID); /* set row ids to quote id */
41
                        $('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */
42
                        $('td:eq(0)', nRow).attr("title", "Click ID to select/deselect quote");
43
                        if (isNaN(quoteID)) {
44
                            noEditFields = [0,1,2,3]; /* all fields when adding a quote */
45
                        }
46
                        else {
47
                            noEditFields = [0,3]; /* id, timestamp */
48
                        }
49
                        /* apply no_edit id to noEditFields */
50
                        for (i=0; i<noEditFields.length; i++) {
51
                            $('td', nRow)[noEditFields[i]].setAttribute("id","no_edit");
52
                        }
53
                        return nRow;
54
                    },
55
                   "fnDrawCallback": function(oSettings) {
56
                        /* Apply the jEditable handlers to the table on all fields w/o the no_edit id */
57
                        $('#quotes_editor tbody td[id!="no_edit"]').editable( "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", {
58
                            "submitdata"    : function ( value, settings ) {
59
                                                  return {
60
                                                      "column"        : oTable.fnGetPosition( this )[2],
61
                                                      "action"        : "edit",
62
                                                  };
63
                                              },
64
                            "height"        : "14px",
65
                            "placeholder"   : "Saving data...",
66
                        });
67
                   },
68
        });
69
    });
70
71
        function fnClickAddQuote(e, node) {
72
            if (e.charCode) {
73
                /* some browsers only give charCode, so this will need to be */
74
                /* fixed up to handle that */
75
                console.log('charCode: '+e.charCode);
76
            }
77
            if (e.keyCode == 13) {
78
                var quoteSource = $('#quoteSource').val();
79
                var quoteText = $('#quoteText').val()
80
                /* If passed a quote source, add the quote to the db */
81
                if (quoteSource && quoteText) {
82
                    $.ajax({
83
                        url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
84
                        type: "POST",
85
                        data: {
86
                                "source"    : quoteSource,
87
                                "text"      : quoteText,
88
                                "action"    : "add",
89
                        },
90
                        success: function(data){
91
                                    var newQuote = data[0];
92
                                    var aRow = oTable.fnUpdate(
93
                                        newQuote,
94
                                        node,
95
                                        false,
96
                                        false
97
                                    );
98
                                    oTable.fnPageChange( 'last' );
99
                                    $('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button
100
                            }
101
                    });
102
                }
103
                else {
104
                    alert('Please supply both the text and source of the quote before saving.');
105
                }
106
            }
107
            else if (e.keyCode == 27) {
108
                if (confirm('Are you sure you want to cancel adding this quote?')) {
109
                    oTable.fnDeleteRow(node);
110
                }
111
                else {
112
                    return;
113
                }
114
            }
115
        }
116
117
        function fnClickAddRow() {
118
            $('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked
119
            var aRow = oTable.fnAddData(
120
                [
121
                    'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list...
122
                    '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
123
                    '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>',
124
                    '0000-00-00 00:00:00',
125
                ],
126
                false
127
            );
128
            oTable.fnPageChange( 'last' );
129
            $('#quoteSource').focus();
130
        }
131
132
        function fnClickDeleteRow() {
133
            var idsToDelete = oTable.$('.selected').map(function() {
134
                  return this.id;
135
            }).get().join(', ');
136
            if (!idsToDelete) {
137
                alert('Please select a quote(s) by clicking the quote id(s) you desire to delete.');
138
            }
139
            else if (confirm('Are you sure you wish to delete quote(s) '+idsToDelete+'?')) {
140
                oTable.$('.selected').each(function(){
141
                        var quoteID = $(this).attr('id');
142
                            $.ajax({
143
                                url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl",
144
                                type: "POST",
145
                                data: {
146
                                        "id"        : quoteID,
147
                                        "action"    : "delete",
148
                                },
149
                                /* Delete the row from the datatable */
150
                                success: function(){
151
                                    oTable.fnDeleteRow(this);
152
                                    oTable.fnReloadAjax(null, null, true);
153
                                }
154
                            });
155
                    });
156
            }
157
            else {
158
                return;
159
            }
160
        }
161
    //]]>
162
    </script>
163
</head>
164
<body id="tools_quotes" class="tools">
165
[% INCLUDE 'header.inc' %]
166
[% INCLUDE 'cat-search.inc' %]
167
168
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Quote Editor</div>
169
170
<div id="doc3" class="yui-t2">
171
    <div id="bd">
172
        <div id="yui-main">
173
            <div class="yui-b">
174
                [% INCLUDE 'quotes-toolbar.inc' %]
175
                <h2>Quote editor</h2>
176
                <table id="quotes_editor" style="float: left; width: 100%;">
177
                <thead>
178
                    <tr>
179
                        <th><span style="cursor: help" onclick="event.stopPropagation();alert('Click on the quote\'s id to select or deselect the quote. Multiple quotes may be selected.');">ID</span></th>
180
                        <th>Source</th>
181
                        <th>Text</th>
182
                        <th>Last Displayed</th>
183
<!--                        <th>Actions</th>-->
184
                    </tr>
185
                </thead>
186
                <tbody>
187
                    <!-- tbody content is generated by DataTables -->
188
                    <tr>
189
                        <td></td>
190
                        <td></td>
191
                        <td>Loading data...</td>
192
                        <td></td>
193
<!--                        <td></td>-->
194
                    </tr>
195
                </tbody>
196
                </table>
197
                <fieldset id="footer" class="action" style="height:25px;">
198
                </fieldset>
199
            </div>
200
        </div>
201
    <div class="yui-b noprint">
202
        [% INCLUDE 'tools-menu.inc' %]
203
    </div>
204
</div>
205
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+4 lines)
Lines 87-92 Link Here
87
    <dd>Schedule tasks to run</dd>
87
    <dd>Schedule tasks to run</dd>
88
    [% END %]
88
    [% END %]
89
	
89
	
90
    [% IF ( CAN_user_tools_edit_quotes ) %]
91
    <dt><a href="/cgi-bin/koha/tools/quotes.pl">Edit Quotes for QOTD Feature</a></dt>
92
    <dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
93
    [% END %]
90
94
91
</dl>
95
</dl>
92
</div>
96
</div>
(-)a/koha-tmpl/opac-tmpl/prog/en/css/opac.css (+23 lines)
Lines 2366-2371 span.sep { Link Here
2366
	text-shadow: 1px 1px 0 #FFF;
2366
	text-shadow: 1px 1px 0 #FFF;
2367
}
2367
}
2368
2368
2369
#daily-quote {
2370
    /*border-top : 1px solid #000000;*/
2371
    border : 1px solid #000000;
2372
    margin-top: 2px;
2373
    margin-bottom: 10px;
2374
    margin-left: 2px;
2375
    margin-right: 2px;
2376
    width: 300px;
2377
    text-align: center;
2378
    font-family: "Georgia","Palatino","Times New Roman",sans-serif;
2379
}
2380
2381
#daily-quote h1 {
2382
    font-size: 18px;
2383
    font-weight: normal;
2384
    margin: 0;
2385
}
2386
2387
#daily-quote div {
2388
    font-size: 12px;
2389
    margin: 5px;
2390
}
2391
2369
/* ## BABELTHEQUE ## */
2392
/* ## BABELTHEQUE ## */
2370
/* Uncomment if babeltheque configuration no contains these lines */
2393
/* Uncomment if babeltheque configuration no contains these lines */
2371
/*
2394
/*
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-main.tt (+4 lines)
Lines 35-40 Link Here
35
</div>
35
</div>
36
[% END %]
36
[% END %]
37
37
38
      [% IF ( display_daily_quote && daily_quote ) %]
39
    <div id="daily-quote" class="container"><h1>Quote of the Day</h1><div><span id="daily-quote-text">[% daily_quote.text %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source %]</span></div></div>
40
[% END %]
41
38
	[% IF ( OpacMainUserBlock ) %]<div id="opacmainuserblock" class="container">[% OpacMainUserBlock %]</div>[% END %]
42
	[% IF ( OpacMainUserBlock ) %]<div id="opacmainuserblock" class="container">[% OpacMainUserBlock %]</div>[% END %]
39
43
40
</div>
44
</div>
(-)a/opac/opac-main.pl (-2 / +7 lines)
Lines 23-28 use C4::Auth; # get_template_and_user Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::NewsChannels;    # get_opac_news
24
use C4::NewsChannels;    # get_opac_news
25
use C4::Languages qw(getTranslatedLanguages accept_language);
25
use C4::Languages qw(getTranslatedLanguages accept_language);
26
use C4::Koha qw( GetDailyQuote );
26
27
27
my $input = new CGI;
28
my $input = new CGI;
28
my $dbh   = C4::Context->dbh;
29
my $dbh   = C4::Context->dbh;
Lines 50-58 my ($theme, $news_lang) = C4::Templates::themelanguage(C4::Context->config('opac Link Here
50
my $all_koha_news   = &GetNewsToDisplay($news_lang);
51
my $all_koha_news   = &GetNewsToDisplay($news_lang);
51
my $koha_news_count = scalar @$all_koha_news;
52
my $koha_news_count = scalar @$all_koha_news;
52
53
54
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
55
53
$template->param(
56
$template->param(
54
    koha_news       => $all_koha_news,
57
    koha_news           => $all_koha_news,
55
    koha_news_count => $koha_news_count
58
    koha_news_count     => $koha_news_count,
59
    display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
60
    daily_quote         => $quote,
56
);
61
);
57
62
58
# If GoogleIndicTransliteration system preference is On Set paramter to load Google's javascript in OPAC search screens
63
# If GoogleIndicTransliteration system preference is On Set paramter to load Google's javascript in OPAC search screens
(-)a/tools/quotes.pl (+44 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2012 Foundations Bible College Inc.
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use CGI;
24
use autouse 'Data::Dumper' => qw(Dumper);
25
26
use C4::Auth;
27
use C4::Koha;
28
use C4::Context;
29
use C4::Output;
30
31
my $cgi = new CGI;
32
33
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34
    {
35
        template_name   => "tools/quotes.tt",
36
        query           => $cgi,
37
        type            => "intranet",
38
        authnotrequired => 0,
39
        flagsrequired   => { tools => 'edit_quotes' },
40
        debug           => 1,
41
    }
42
);
43
44
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/tools/quotes/quotes_ajax.pl (-1 / +116 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2012 Foundations Bible College Inc.
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use CGI;
24
use JSON;
25
use autouse 'Data::Dumper' => qw(Dumper);
26
27
use C4::Auth;
28
use C4::Context;
29
30
my $cgi = CGI->new;
31
my $dbh = C4::Context->dbh;
32
my $sort_columns = ["id", "source", "text", "timestamp"];
33
34
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35
    {
36
        template_name   => "",
37
        query           => $cgi,
38
        type            => "intranet",
39
        authnotrequired => 0,
40
        flagsrequired   => { tools => 'edit_quotes' },
41
        debug           => 1,
42
    }
43
);
44
45
# NOTE: This is a collection of ajax functions for use with tools/quotes.pl
46
47
my $params = $cgi->Vars; # NOTE: Multivalue parameters NOT allowed!!
48
49
print $cgi->header('application/json');
50
51
if ($params->{'action'} eq 'add') {
52
    my $sth = $dbh->prepare('INSERT INTO quotes (source, text) VALUES (?, ?);');
53
    $sth->execute($params->{'source'}, $params->{'text'});
54
    if ($sth->err) {
55
        warn sprintf('Database returned the following error: %s', $sth->errstr);
56
        exit 0;
57
    }
58
    my $new_quote_id = $dbh->{q{mysql_insertid}}; # ALERT: mysqlism here
59
    $sth = $dbh->prepare('SELECT * FROM quotes WHERE id = ?;');
60
    $sth->execute($new_quote_id);
61
    print to_json($sth->fetchall_arrayref);
62
    exit 1;
63
}
64
elsif ($params->{'action'} eq 'edit') {
65
    my $editable_columns = [qw(source text)]; # pay attention to element order; these columns match the quotes table columns
66
    my $sth = $dbh->prepare("UPDATE quotes SET $editable_columns->[$params->{'column'}-1]  = ? WHERE id = ?;");
67
    $sth->execute($params->{'value'}, $params->{'id'});
68
    if ($sth->err) {
69
        warn sprintf('Database returned the following error: %s', $sth->errstr);
70
        exit 0;
71
    }
72
    print $sth->fetchrow_array();
73
    exit 1;
74
}
75
elsif ($params->{'action'} eq 'delete') {
76
    my $sth = $dbh->prepare("DELETE FROM quotes WHERE id = ?;");
77
    $sth->execute($params->{'id'});
78
    if ($sth->err) {
79
        warn sprintf('Database returned the following error: %s', $sth->errstr);
80
        exit 0;
81
    }
82
    exit 1;
83
}
84
else {
85
    my $aaData = [];
86
    my $iTotalRecords = '';
87
    my $sth = '';
88
89
    if (my $filter = $params->{'sSearch'}) {
90
        # This seems a bit brute force and ungraceful, but it provides a very general, simple search on all fields
91
        my $like = " id LIKE \"%$filter%\" OR source LIKE \"%$filter%\" OR text LIKE \"%$filter%\" OR timestamp LIKE \"%$filter%\"";
92
        $iTotalRecords = $dbh->selectrow_array("SELECT count(*) FROM quotes WHERE $like;");
93
        $sth = $dbh->prepare("SELECT * FROM quotes;");
94
    }
95
    else {
96
        $iTotalRecords = $dbh->selectrow_array('SELECT count(*) FROM quotes;');
97
        $sth = $dbh->prepare("SELECT * FROM quotes;");
98
    }
99
100
    $sth->execute();
101
    if ($sth->err) {
102
        warn sprintf('Database returned the following error: %s', $sth->errstr);
103
        exit 0;
104
    }
105
106
    $aaData = $sth->fetchall_arrayref;
107
    my $iTotalDisplayRecords = $iTotalRecords; # no filtering happening here
108
109
110
    print to_json({
111
                    iTotalRecords       =>  $iTotalRecords,
112
                    iTotalDisplayRecords=>  $iTotalDisplayRecords,
113
                    sEcho               =>  $params->{'sEcho'},
114
                    aaData              =>  $aaData,
115
                  });
116
}

Return to bug 7977