diff --git a/doc/lms.mysql b/doc/lms.mysql index 22a3790e87..091a84364f 100644 --- a/doc/lms.mysql +++ b/doc/lms.mysql @@ -1124,6 +1124,8 @@ CREATE TABLE promotionschemas ( disabled tinyint(1) DEFAULT '0' NOT NULL, deleted tinyint(1) DEFAULT 0 NOT NULL, length tinyint(1) DEFAULT NULL, + datefrom int(11) DEFAULT 0 NOT NULL, + dateto int(11) DEFAULT 0 NOT NULL, PRIMARY KEY (id), UNIQUE KEY promotionid (promotionid, name), FOREIGN KEY (promotionid) REFERENCES promotions (id) ON DELETE CASCADE ON UPDATE CASCADE @@ -4145,4 +4147,4 @@ INSERT INTO netdevicemodels (name, alternative_name, netdeviceproducerid) VALUES ('XR7', 'XR7 MINI PCI PCBA', 2), ('XR9', 'MINI PCI 600MW 900MHZ', 2); -INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021100500'); +INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021101900'); diff --git a/doc/lms.pgsql b/doc/lms.pgsql index 4cc76c60a7..ef7869cb73 100644 --- a/doc/lms.pgsql +++ b/doc/lms.pgsql @@ -980,6 +980,8 @@ CREATE TABLE promotionschemas ( disabled smallint DEFAULT 0 NOT NULL, deleted smallint DEFAULT 0 NOT NULL, length smallint DEFAULT NULL, + datefrom integer DEFAULT 0 NOT NULL, + dateto integer DEFAULT 0 NOT NULL, PRIMARY KEY (id), CONSTRAINT promotionschemas_promotionid_key UNIQUE (promotionid, name) ); @@ -4162,6 +4164,6 @@ INSERT INTO netdevicemodels (name, alternative_name, netdeviceproducerid) VALUES ('XR7', 'XR7 MINI PCI PCBA', 2), ('XR9', 'MINI PCI 600MW 900MHZ', 2); -INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021100500'); +INSERT INTO dbinfo (keytype, keyvalue) VALUES ('dbversion', '2021101900'); COMMIT; diff --git a/lib/LMSDB_common.class.php b/lib/LMSDB_common.class.php index a1b1581784..18c1e390dd 100644 --- a/lib/LMSDB_common.class.php +++ b/lib/LMSDB_common.class.php @@ -24,7 +24,7 @@ * $Id$ */ -define('DBVERSION', '2021100500'); // here should be always the newest version of database! +define('DBVERSION', '2021101900'); // here should be always the newest version of database! /** * diff --git a/lib/locale/pl_PL/strings.php b/lib/locale/pl_PL/strings.php index 4ce108650c..2ffb778b02 100644 --- a/lib/locale/pl_PL/strings.php +++ b/lib/locale/pl_PL/strings.php @@ -3301,6 +3301,7 @@ $_LANG['New Promotion'] = 'Nowa promocja'; $_LANG['New Schema'] = 'Nowy schemat'; $_LANG['Periods:'] = 'Okresy:'; +$_LANG['Periods'] = 'Okresy'; $_LANG['Promotion:'] = 'Promocja:'; $_LANG['Promotions'] = 'Promocje'; $_LANG['Promotions:'] = 'Promocje:'; diff --git a/lib/upgradedb/mysql.2021101900.php b/lib/upgradedb/mysql.2021101900.php new file mode 100644 index 0000000000..2335a2a8e9 --- /dev/null +++ b/lib/upgradedb/mysql.2021101900.php @@ -0,0 +1,31 @@ +BeginTrans(); + +$this->Execute("ALTER TABLE promotionschemas ADD COLUMN datefrom int(11) DEFAULT 0 NOT NULL"); +$this->Execute("ALTER TABLE promotionschemas ADD COLUMN dateto int(11) DEFAULT 0 NOT NULL"); + +$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2021101900', 'dbversion')); + +$this->CommitTrans(); diff --git a/lib/upgradedb/postgres.2021101900.php b/lib/upgradedb/postgres.2021101900.php new file mode 100644 index 0000000000..eda7a6b0b2 --- /dev/null +++ b/lib/upgradedb/postgres.2021101900.php @@ -0,0 +1,33 @@ +BeginTrans(); + +$this->Execute(" + ALTER TABLE promotionschemas ADD COLUMN datefrom integer DEFAULT 0 NOT NULL; + ALTER TABLE promotionschemas ADD COLUMN dateto integer DEFAULT 0 NOT NULL +"); + +$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2021101900', 'dbversion')); + +$this->CommitTrans(); diff --git a/modules/promotionadd.php b/modules/promotionadd.php index fdd9b48e3a..cec7bb399d 100644 --- a/modules/promotionadd.php +++ b/modules/promotionadd.php @@ -3,7 +3,7 @@ /* * LMS version 1.11-git * - * (C) Copyright 2001-2016 LMS Developers + * (C) Copyright 2001-2021 LMS Developers * * Please, see the doc/AUTHORS for more information about authors! * @@ -41,34 +41,16 @@ $error['name'] = trans('Specified name is in use!'); } - if (empty($promotion['datefrom'])) { - $promotion['from'] = 0; - } else { - $from = date_to_timestamp($promotion['datefrom']); - if (empty($from)) { - $error['datefrom'] = trans('Incorrect effective start time!'); - } - } - - if (empty($promotion['dateto'])) { - $promotion['to'] = 0; - } else { - $to = date_to_timestamp($promotion['dateto']); - if (empty($to)) { - $error['dateto'] = trans('Incorrect effective start time!'); - } - } - - if ($promotion['to'] != 0 && $promotion['from'] != 0 && $to < $from) { - $error['dateto'] = trans('Incorrect date range!'); + if (!empty($promotion['dateto']) && !empty($promotion['datefrom']) && $promotion['dateto'] < $promotion['from']) { + $error['dateto'] = trans('Incorrect date range!'); } if (!$error) { $args = array( 'name' => $promotion['name'], 'description' => $promotion['description'], - 'datefrom' => $promotion['from'], - 'dateto' => $promotion['to'], + 'datefrom' => $promotion['datefrom'] ?: 0, + 'dateto' => $promotion['dateto'] ? strtotime('tomorrow', $promotion['dateto']) - 1 : 0, ); $DB->Execute('INSERT INTO promotions (name, description, datefrom, dateto) VALUES (?, ?, ?, ?)', array_values($args)); diff --git a/modules/promotionedit.php b/modules/promotionedit.php index bfb23ac72f..4eb40a6c93 100644 --- a/modules/promotionedit.php +++ b/modules/promotionedit.php @@ -3,7 +3,7 @@ /* * LMS version 1.11-git * - * (C) Copyright 2001-2016 LMS Developers + * (C) Copyright 2001-2021 LMS Developers * * Please, see the doc/AUTHORS for more information about authors! * @@ -88,25 +88,7 @@ $promotion['name'] = $oldpromotion['name']; } - if (empty($promotion['datefrom'])) { - $promotion['from'] = 0; - } else { - $from = date_to_timestamp($promotion['datefrom']); - if (empty($from)) { - $error['datefrom'] = trans('Incorrect effective start time!'); - } - } - - if (empty($promotion['dateto'])) { - $promotion['to'] = 0; - } else { - $to = date_to_timestamp($promotion['dateto']); - if (empty($to)) { - $error['dateto'] = trans('Incorrect effective start time!'); - } - } - - if ($promotion['to'] != 0 && $promotion['from'] != 0 && $to < $from) { + if (!empty($promotion['dateto']) && !empty($promotion['datefrom']) && $promotion['dateto'] < $promotion['datefrom']) { $error['dateto'] = trans('Incorrect date range!'); } @@ -114,12 +96,16 @@ $args = array( 'name' => $promotion['name'], 'description' => $promotion['description'], - 'datefrom' => $promotion['from'], - 'dateto' => $promotion['to'], + 'datefrom' => $promotion['datefrom'] ?: 0, + 'dateto' => $promotion['dateto'] ? strtotime('tomorrow', $promotion['dateto']) - 1 : 0, SYSLOG::RES_PROMO => $promotion['id'] ); - $DB->Execute('UPDATE promotions SET name = ?, description = ?, datefrom = ?, dateto = ? - WHERE id = ?', array_values($args)); + $DB->Execute( + 'UPDATE promotions + SET name = ?, description = ?, datefrom = ?, dateto = ? + WHERE id = ?', + array_values($args) + ); if ($SYSLOG) { $SYSLOG->AddMessage(SYSLOG::RES_PROMO, SYSLOG::OPER_UPDATE, $args); @@ -129,14 +115,6 @@ } } else { $promotion = $LMS->getPromotion($promotionid); - - if ($promotion['datefrom']) { - $promotion['datefrom'] = date('Y/m/d', $promotion['datefrom']); - } - - if ($promotion['dateto']) { - $promotion['dateto'] = date('Y/m/d', $promotion['dateto']); - } } $layout['pagetitle'] = trans('Promotion Edit: $a', $promotion['name']); diff --git a/modules/promotioninfo.php b/modules/promotioninfo.php index 6db9f79974..a3629ad880 100644 --- a/modules/promotioninfo.php +++ b/modules/promotioninfo.php @@ -42,7 +42,7 @@ $promotion['schemas'] = $DB->GetAllByKey( 'SELECT - s.name, s.disabled, s.description, s.id, s.deleted, + s.name, s.disabled, s.description, s.id, s.deleted, s.datefrom, s.dateto, COUNT(a.id) AS assignments FROM promotionschemas s LEFT JOIN assignments a ON a.promotionschemaid = s.id diff --git a/modules/promotionschemaadd.php b/modules/promotionschemaadd.php index 21b46078d1..a2bcb49b54 100644 --- a/modules/promotionschemaadd.php +++ b/modules/promotionschemaadd.php @@ -3,7 +3,7 @@ /* * LMS version 1.11-git * - * (C) Copyright 2001-2016 LMS Developers + * (C) Copyright 2001-2021 LMS Developers * * Please, see the doc/AUTHORS for more information about authors! * @@ -46,6 +46,10 @@ $error['name'] = trans('Specified name is in use!'); } + if (!empty($schema['dateto']) && !empty($schema['datefrom']) && $schema['dateto'] < $schema['datefrom']) { + $error['dateto'] = trans('Incorrect date range!'); + } + if (!$error) { $length = 0; $data = array(); @@ -65,10 +69,12 @@ 'description' => $schema['description'], 'data' => $data, 'length' => $length, + 'datefrom' => $schema['datefrom'] ?: 0, + 'dateto' => $schema['dateto'] ? strtotime('tomorrow', $schema['dateto']) - 1 : 0, ); $DB->Execute('INSERT INTO promotionschemas (promotionid, name, - description, data, length) - VALUES (?, ?, ?, ?, ?)', array_values($args)); + description, data, length, datefrom, dateto) + VALUES (?, ?, ?, ?, ?, ?, ?)', array_values($args)); $sid = $DB->GetLastInsertId('promotionschemas'); diff --git a/modules/promotionschemaedit.php b/modules/promotionschemaedit.php index c5cdc4c507..d7ba0248bd 100644 --- a/modules/promotionschemaedit.php +++ b/modules/promotionschemaedit.php @@ -3,7 +3,7 @@ /* * LMS version 1.11-git * - * (C) Copyright 2001-2020 LMS Developers + * (C) Copyright 2001-2021 LMS Developers * * Please, see the doc/AUTHORS for more information about authors! * @@ -291,6 +291,10 @@ } } + if (!empty($schema['dateto']) && !empty($schema['datefrom']) && $schema['dateto'] < $schema['datefrom']) { + $error['dateto'] = trans('Incorrect date range!'); + } + if (!$error && !$warning) { $DB->BeginTrans(); @@ -299,10 +303,16 @@ 'description' => $schema['description'], 'data' => empty($oldschema['assignmentcount']) || ConfigHelper::checkPrivilege('superuser') ? implode(';', $data) : $oldschema['data'], 'length' => $length, + 'datefrom' => $schema['datefrom'] ?: 0, + 'dateto' => $schema['dateto'] ? strtotime('tomorrow', $schema['dateto']) - 1 : 0, SYSLOG::RES_PROMOSCHEMA => $schema['id'], ); - $DB->Execute('UPDATE promotionschemas SET name = ?, description = ?, data = ?, length = ? - WHERE id = ?', array_values($args)); + $DB->Execute( + 'UPDATE promotionschemas + SET name = ?, description = ?, data = ?, length = ?, datefrom = ?, dateto = ? + WHERE id = ?', + array_values($args) + ); if ($SYSLOG) { $args[SYSLOG::RES_PROMO] = $oldschema['promotionid']; diff --git a/modules/promotionschemainfo.php b/modules/promotionschemainfo.php index e2264843e7..c2043fa5b7 100644 --- a/modules/promotionschemainfo.php +++ b/modules/promotionschemainfo.php @@ -26,7 +26,7 @@ $schema = $DB->GetRow( 'SELECT - s.id, s.name, s.description, s.data, s.disabled, s.deleted, s.length, + s.id, s.name, s.description, s.data, s.disabled, s.deleted, s.length, s.datefrom, s.dateto, p.id AS pid, p.name AS promotion, COUNT(a.id) AS assignments FROM promotionschemas s diff --git a/templates/default/promotion/promotionadd.html b/templates/default/promotion/promotionadd.html index d2a7e5ea8b..0f88c433e8 100644 --- a/templates/default/promotion/promotionadd.html +++ b/templates/default/promotion/promotionadd.html @@ -2,52 +2,82 @@ {block name=title}LMS: {$layout.pagetitle|striphtml}{/block} {block name=module_content} -

{$layout.pagetitle}

-
-

- -

- - - - - - - - - - - - - - - - - - -
- {icon name="money"} - - {trans("Name:")} - - -
- {icon name="optional-info"} - - {trans("Description:")} - - -
- {button icon="save" label="Submit" onclick="document.promotionadd.submit();"} - {button icon="cancel" label="Cancel" href="?m=promotionlist"} - -
+

{$layout.pagetitle}

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {icon name="money"} + + {trans("Name")} + + +
+ {icon name="period"} + + {trans("Period")} + + {trans("from")} + + {trans("to")} + +
+ {icon name="optional-info"} + + {trans("Description")} + + +
+ {button type="submit" icon="save" label="Submit" form="promotionadd"} + {button icon="cancel" label="Cancel" href="?m=promotionlist"} + +
+ {/block} diff --git a/templates/default/promotion/promotionedit.html b/templates/default/promotion/promotionedit.html index 21954e53a9..84aa7ae6bc 100644 --- a/templates/default/promotion/promotionedit.html +++ b/templates/default/promotion/promotionedit.html @@ -2,59 +2,80 @@ {block name=title}LMS: {$layout.pagetitle|striphtml}{/block} {block name=module_content} -

{$layout.pagetitle}

-
-

- -

- +

{$layout.pagetitle}

+ + + + +
- - - - - - - - - - - - - - - - - -
- {icon name="money"} - - {trans("Name:")} - - -
- {icon name="optional-info"} - - {trans("Description:")} - - -
- {button icon="save" label="Submit" onclick="document.promotionedit.submit();"} - {button icon="cancel" label="Cancel" href="?m=promotionlist"} -
- + + + + {icon name="money"} + + + {trans("Name")} + + + + + + + + + + {icon name="period"} + + + {trans("Period")} + + + {trans("from")} + + {trans("to")} + + + + + + {icon name="optional-info"} + + + {trans("Description")} + + + + + + + + {button type="submit" icon="save" label="Submit" form="promotionedit"} + {button icon="cancel" label="Cancel" href="?m=promotionlist"} + + + + + {/block} diff --git a/templates/default/promotion/promotioninfobox.html b/templates/default/promotion/promotioninfobox.html index 9aea6bc903..a554d0ca1f 100644 --- a/templates/default/promotion/promotioninfobox.html +++ b/templates/default/promotion/promotioninfobox.html @@ -1,60 +1,85 @@ - - - - - - - - - - - - - {if $promotion.description} - - - - - {/if} - - - - -
- {icon name="money"} - - {$promotion.name} ({$promotion.id|string_format:"%04d"}) - {if $promotion.deleted} ({trans("deleted promotion")}){/if} -
- {if $promotion.disabled} - {button type="link" icon="disconnected" tip="Enable" href="?m=promotionset&id={$promotion.id}&access={$promotion.disabled}"} - {else} - {button type="link" icon="connected" tip="Disable" href="?m=promotionset&id={$promotion.id}&access={$promotion.disabled}"} - {/if} - - {if $promotion.disabled}{trans("disabled")}{else}{trans("enabled")}{/if} -
- {icon name="optional-info"} - - - -
- {$promotion.description|replace:"\n":"
"} -
-
- {if !$promotion.deleted} - {button icon="edit" label="Edit" href="?m=promotionedit&id={$promotion.id}"} - {/if} - {if !$promotion.deleted || !$promotion.assignments} - {button icon="delete" label="Delete" id="delete-promotion" data_href="?m=promotiondel&id={$promotion.id}"} - {/if} -
+ + + + + + + + + + + + + + {if $promotion.datefrom || $promotion.dateto} + + + + + {/if} + + + + + {if $promotion.description} + + + + + {/if} + + + + +
+ {icon name="money"} + + {$promotion.name|escape} ({$promotion.id|string_format:"%04d"}) + {if $promotion.deleted} ({trans("deleted promotion")}){/if} +
+ {icon name="period"} + + {if $promotion.datefrom} + {trans("from")} {$promotion.datefrom|date_format:"%Y/%m/%d"} + {/if} + {if $promotion.dateto} + {trans("to")} {$promotion.dateto|date_format:"%Y/%m/%d"} + {/if} +
+ {if $promotion.disabled} + {button type="link" icon="disconnected" tip="Enable" href="?m=promotionset&id={$promotion.id}&access={$promotion.disabled}"} + {else} + {button type="link" icon="connected" tip="Disable" href="?m=promotionset&id={$promotion.id}&access={$promotion.disabled}"} + {/if} + + {if $promotion.disabled}{trans("disabled")}{else}{trans("enabled")}{/if} +
+ {icon name="optional-info"} + + + +
+ {$promotion.description|escape|replace:"\n":"
"} +
+
+ {if !$promotion.deleted} + {button icon="edit" label="Edit" href="?m=promotionedit&id={$promotion.id}"} + {/if} + {if !$promotion.deleted || !$promotion.assignments} + {button icon="delete" label="Delete" id="delete-promotion" data_href="?m=promotiondel&id={$promotion.id}"} + {/if} +
+ diff --git a/templates/default/promotion/promotionlist.html b/templates/default/promotion/promotionlist.html index 8a4d0052f5..137fa71986 100644 --- a/templates/default/promotion/promotionlist.html +++ b/templates/default/promotion/promotionlist.html @@ -41,29 +41,29 @@

{$layout.pagetitle}

{foreach $promotionlist as $promo} - - {icon name="money"} {$promo.name} + + {icon name="money"} {$promo.name|escape} {if $promo.datefrom || $promo.dateto} {if $promo.datefrom} - ({trans("from:")} {$promo.datefrom|date_format:"%Y/%m/%d"}{if !$promo.dateto}){/if} + ({trans("from")} {$promo.datefrom|date_format:"%Y/%m/%d"}{if !$promo.dateto}){/if} {/if} {if $promo.dateto} - {if !$promo.datefrom}({/if}{trans("to:")} {$promo.dateto|date_format:"%Y/%m/%d"}) + {if !$promo.datefrom}({/if}{trans("to")} {$promo.dateto|date_format:"%Y/%m/%d"}) {/if} {/if} - + ({$promo.id|string_format:"%04d"}) - - {$promo.description} - - + + {$promo.description|escape} + + {$promo.scs|default:"-"} - - + + {$promo.tariffs|default:"-"} - + {$promo.assignments|default:"-"} diff --git a/templates/default/promotion/promotionschemaadd.html b/templates/default/promotion/promotionschemaadd.html index 225d02ece2..5281b1e02f 100644 --- a/templates/default/promotion/promotionschemaadd.html +++ b/templates/default/promotion/promotionschemaadd.html @@ -16,86 +16,108 @@ -

{$layout.pagetitle}

-

{trans("Promotion:")} {$schema.promotionname}

-
-

- -

- +

{$layout.pagetitle}

+

{trans("Promotion:")} {$schema.promotionname}

+ + + + +
- - - - - - - - - - - - - - - - - - - - - - -
- {icon name="money"} - - {trans("Name:")} - - -
- {icon name="calendar"} - - {trans("Periods:")} - - {foreach $schema.periods as $key => $period} - - {/foreach} - {if count($schema.periods) < 2} - {$visible = false} - {else} - {$visible = true} - {/if} - {button type="link" icon="delete" tip="Delete" id="perioddel" visible=$visible} - {button type="link" icon="add" tip="Add" id="periodadd"} -
- {icon name="info"} - - {trans("Description:")} - - -
-
- {button type="submit" icon="save" label="Submit"} - {button icon="cancel" label="Cancel" href="?m=promotioninfo&id={$schema.promotionid}"} - -
-
- + + + + {icon name="money"} + + + {trans("Name")} + + + + + + + + + + {icon name="calendar"} + + + {trans("Periods")} + + + {foreach $schema.periods as $key => $period} + + {/foreach} + {if count($schema.periods) < 2} + {$visible = false} + {else} + {$visible = true} + {/if} + {button type="link" icon="delete" tip="Delete" id="perioddel" visible=$visible} + {button type="link" icon="add" tip="Add" id="periodadd"} + + + + + {icon name="period"} + + + {trans("Period")} + + + {trans("from")} + + {trans("to")} + + + + + + {icon name="info"} + + + {trans("Description")} + + + + + + + +
+ {button type="submit" icon="save" label="Submit" form="schemaadd"} + {button icon="cancel" label="Cancel" href="?m=promotioninfo&id={$schema.promotionid}"} + +
+ + + + +