1: <?php
2:
3:
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
9: }
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: class CreateArticle extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: protected $BO;
64:
65: 66: 67: 68: 69: 70:
71: private static $logger = null;
72:
73: 74: 75: 76: 77:
78: public function __construct() {
79: self::$logger = new Logger('CreateArticle');
80: self::$logger->debug('>>__construct()');
81:
82: global $config;
83:
84:
85: parent::__construct('Standard');
86:
87: $this->BO = new ArticleObject();
88:
89:
90: $this->setTitle('Create a new Article');
91: $this->setDescription('Page to create a new article.');
92: $this->setKeywords('create,new,article');
93:
94: self::$logger->debug('<<__construct');
95: }
96:
97: 98: 99: 100: 101: 102:
103: public function doGET($params) {
104: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
105:
106: echo AlphaView::displayPageHead($this);
107:
108: $view = AlphaView::getInstance($this->BO);
109:
110: echo $view->createView();
111:
112: echo AlphaView::displayPageFoot($this);
113:
114: self::$logger->debug('<<doGET');
115: }
116:
117: 118: 119: 120: 121: 122: 123:
124: public function doPOST($params) {
125: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
126:
127: global $config;
128:
129: try {
130:
131: if(!$this->checkSecurityFields())
132: throw new SecurityException('This page cannot accept post data from remote servers!');
133:
134: $this->BO = new ArticleObject();
135:
136: if (isset($params['createBut'])) {
137:
138: $this->BO->populateFromPost();
139:
140: $this->BO->save();
141:
142: self::$logger->action('Created new ArticleObject instance with OID '.$this->BO->getOID());
143:
144: AlphaDAO::disconnect();
145:
146: try {
147: if ($this->getNextJob() != '')
148: header('Location: '.$this->getNextJob());
149: else
150: header('Location: '.FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getID()));
151: }catch(AlphaException $e) {
152: self::$logger->error($e->getTraceAsString());
153: echo '<p class="error"><br>Error creating the new article, check the log!</p>';
154: }
155: }
156:
157: if (isset($params['cancelBut'])) {
158: header('Location: '.FrontController::generateSecureURL('act=ListBusinessObjects'));
159: }
160: }catch(SecurityException $e) {
161: echo AlphaView::displayPageHead($this);
162: echo '<p class="error"><br>'.$e->getMessage().'</p>';
163: self::$logger->warn($e->getMessage());
164: }
165:
166: self::$logger->debug('<<doPOST');
167: }
168:
169: 170: 171: 172: 173: 174:
175: public function during_displayPageHead_callback() {
176: global $config;
177:
178: $html = '
179: <script type="text/javascript">
180: var previewURL = "'.FrontController::generateSecureURL('act=PreviewArticle&bo=ArticleObject').'";
181: </script>
182: <script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/markitup/jquery.markitup.js"></script>
183: <script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/markitup/sets/markdown/set.js"></script>
184: <link rel="stylesheet" type="text/css" href="'.$config->get('app.url').'alpha/lib/markitup/skins/simple/style.css" />
185: <link rel="stylesheet" type="text/css" href="'.$config->get('app.url').'alpha/lib/markitup/sets/markdown/style.css" />
186: <script type="text/javascript">
187: $(document).ready(function() {
188: $(\'[id="'.($config->get('security.encrypt.http.fieldnames') ? 'text_field_'.base64_encode(AlphaSecurityUtils::encrypt('content')).'_0' : 'text_field_content_0').'"]\').markItUp(mySettings);
189:
190: var dialogCoords = [(screen.width/2)-400, (screen.height/2)-300];
191:
192: var dialogOpts = {
193: title: "Help Page",
194: modal: true,
195: resizable: false,
196: draggable: false,
197: autoOpen: false,
198: height: 400,
199: width: 800,
200: position: dialogCoords,
201: buttons: {},
202: open: function() {
203: //display correct dialog content
204: $("#helpPage").load("'.FrontController::generateSecureURL('act=ViewArticleFile&file=Markdown_Help.text').'");
205: },
206: close: function() {
207:
208: $("#helpPage").dialog(dialogOpts);
209:
210: $(".markItUpButton15").click(
211: function (){
212: $("#helpPage").dialog("open");
213: return false;
214: }
215: );
216: }
217: };
218:
219: $("#helpPage").dialog(dialogOpts);
220:
221: $(".markItUpButton15").click(
222: function (){
223: $("#helpPage").dialog("open");
224: return false;
225: }
226: );
227: });
228: </script>';
229:
230: return $html;
231: }
232:
233: 234: 235: 236: 237: 238:
239: public function after_displayPageHead_callback() {
240: $menu = '';
241:
242: if (isset($_SESSION['currentUser']) && AlphaDAO::isInstalled() && $_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
243: $menu .= AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
244: }
245:
246: return $menu;
247: }
248: }
249:
250:
251: if(basename($_SERVER['PHP_SELF']) == 'CreateArticle.php') {
252: $controller = new CreateArticle();
253:
254: if(!empty($_POST)) {
255: $controller->doPOST($_REQUEST);
256: }else{
257: $controller->doGET($_GET);
258: }
259: }
260:
261: ?>