Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
created

class/template.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * ****************************************************************************
4
 *  - A Project by Developers TEAM For Xoops - ( http://www.xoops.org )
5
 * ****************************************************************************
6
 *  XNEWSLETTER - MODULE FOR XOOPS
7
 *  Copyright (c) 2007 - 2012
8
 *  Goffy ( wedega.com )
9
 *
10
 *  You may not change or alter any portion of this comment or credits
11
 *  of supporting developers from this source code or any supporting
12
 *  source code which is considered copyrighted (c) material of the
13
 *  original comment or credit authors.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *  ---------------------------------------------------------------------------
20
 */
21
 /**
22
 * ****************************************************************************
23
 * @copyright  Goffy ( wedega.com )
24
 * @license    GNU General Public License 2.0
25
 * @package    xnewsletter
26
 * @author     Goffy ( [email protected] )
27
 *
28
 *  Version : $Id $
29
 * ****************************************************************************
30
 */
31
32
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
33
include_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class XnewsletterTemplate
37
 */
38
class XnewsletterTemplate extends XoopsObject
39
{
40
    /**
41
     *
42
     * @var object xnewsletterxnewsletter
43
     */
44
    public $xnewsletter = null;
45
46
    /**
47
     * Class constructor
48
     */
49 View Code Duplication
    public function __construct()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
52
        $this->db          = XoopsDatabaseFactory::getDatabaseConnection();
53
        $this->initVar("template_id", XOBJ_DTYPE_INT, null, false, 8);
54
        $this->initVar("template_title", XOBJ_DTYPE_TXTBOX, null, false, 100);
55
        $this->initVar("template_description", XOBJ_DTYPE_TXTAREA, null, false);
56
        $this->initVar("template_content", XOBJ_DTYPE_TXTAREA, null, false);
57
        $this->initVar("template_submitter", XOBJ_DTYPE_INT, null, false, 10);
58
        $this->initVar("template_created", XOBJ_DTYPE_INT, null, false, 10);
59
    }
60
61
    /**
62
     * @param bool $action
63
     *
64
     * @return XoopsThemeForm
65
     */
66
    public function getForm($action = false)
67
    {
68
        global $xoopsDB;
69
70
        if ($action === false) {
71
            $action = $_SERVER["REQUEST_URI"];
72
        }
73
74
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TEMPLATE_ADD) : sprintf(_AM_XNEWSLETTER_TEMPLATE_EDIT);
75
76
        include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
77
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
78
        $form->setExtra('enctype="multipart/form-data"');
79
80
        $form->addElement(new XoopsFormText(_AM_XNEWSLETTER_TEMPLATE_TITLE, "template_title", 50, 255, $this->getVar("template_title", 'e')), true);
81
82
        $editor_configs           = array();
83
        $editor_configs["name"]   = "template_description";
84
        $editor_configs["value"]  = $this->getVar("template_description", "e");
85
        $editor_configs["rows"]   = 10;
86
        $editor_configs["cols"]   = 80;
87
        $editor_configs["width"]  = "100%";
88
        $editor_configs["height"] = "400px";
89
        $editor_configs["editor"] = $this->xnewsletter->getConfig('xnewsletter_editor');
90
        $template_description_editor = new XoopsFormEditor(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION, "template_description", $editor_configs);
91
        $template_description_editor->setDescription(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION_DESC);
92
        $form->addElement($template_description_editor, false);
93
94
        $editor_configs           = array();
95
        $editor_configs["name"]   = "template_content";
96
        $editor_configs["value"]  = $this->getVar("template_content", "e");
97
        $editor_configs["rows"]   = 10;
98
        $editor_configs["cols"]   = 80;
99
        $editor_configs["width"]  = "100%";
100
        $editor_configs["height"] = "400px";
101
        $editor_configs["editor"] = $this->xnewsletter->getConfig('template_editor');
102
        $template_content_editor = new XoopsFormEditor(_AM_XNEWSLETTER_TEMPLATE_CONTENT, "template_content", $editor_configs);
103
        $template_content_editor->setDescription(_AM_XNEWSLETTER_TEMPLATE_CONTENT_DESC);
104
        $form->addElement($template_content_editor, true);
105
106
        $time = ($this->isNew()) ? time() : $this->getVar("template_created");
107
        $form->addElement(new XoopsFormHidden("template_submitter", $GLOBALS['xoopsUser']->uid()));
108
        $form->addElement(new XoopsFormHidden("template_created", $time));
109
110
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
111
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_CREATED, formatTimestamp($time, 's')));
112
113
        //$form->addElement(new XoopsFormSelectUser(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, "template_submitter", false, $this->getVar("template_submitter"), 1, false), true);
114
        //$form->addElement(new XoopsFormTextDateSelect(_AM_XNEWSLETTER_TEMPLATE_CREATED, "template_created", "", $this->getVar("template_created")));
115
116
        $form->addElement(new XoopsFormHidden("op", "save_template"));
117
        $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
118
119
        return $form;
120
    }
121
}
122
123
/**
124
 * Class XnewsletterTemplateHandler
125
 */
126 View Code Duplication
class XnewsletterTemplateHandler extends XoopsPersistableObjectHandler
127
{
128
    /**
129
     * @var xnewsletterxnewsletter
130
     * @access public
131
     */
132
    public $xnewsletter = null;
133
134
    /**
135
     * @param null|object $db
136
     */
137
    public function __construct(&$db)
138
    {
139
        parent::__construct($db, "xnewsletter_template", "XnewsletterTemplate", "template_id", "template_title");
140
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
141
    }
142
}
143