1: 2: 3: 4: 5: 6: 7: 8: 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: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642:
<?php
defined('ICMS_ROOT_PATH') or die("ImpressCMS root path not defined");
class icms_ipf_Controller {
public $handler;
public function __construct($handler) {
$this->handler=$handler;
}
public function postDataToObject(&$icmsObj) {
foreach (array_keys($icmsObj->vars) as $key) {
$control = $icmsObj->getControl($key);
if (is_array($control) && isset($control['name']) && $control['name'] == "label") continue;
switch ($icmsObj->vars[$key]['data_type']) {
case XOBJ_DTYPE_IMAGE:
if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !='') {
$_POST['url_' . $key] = preg_replace('|[\.]+\/|', './', $_POST['url_' . $key]);
$eventResult = $this->handler->executeEvent('beforeFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the beforeFileUnlink event");
}
$oldFile = $icmsObj->getUploadDir(true) . $icmsObj->getVar($key, 'e');
$icmsObj->setVar($key, $_POST['url_' . $key]);
if (is_file($oldFile) ) unlink($oldFile);
$eventResult = $this->handler->executeEvent('afterFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the afterFileUnlink event");
}
}
if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
$eventResult = $this->handler->executeEvent('beforeFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the beforeFileUnlink event");
}
$oldFile = $icmsObj->getUploadDir(true) . $icmsObj->getVar($key, 'e');
$icmsObj->setVar($key, '');
if (is_file($oldFile) ) unlink($oldFile);
$eventResult = $this->handler->executeEvent('afterFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the afterFileUnlink event");
}
}
break;
case XOBJ_DTYPE_URLLINK:
$linkObj = $icmsObj->getUrlLinkObj($key);
$linkObj->setVar('mid', $_POST['mid_' . $key]);
$linkObj->setVar('caption', $_POST['caption_' . $key]);
$linkObj->setVar('description', $_POST['desc_' . $key]);
$linkObj->setVar('target', $_POST['target_' . $key]);
$linkObj->setVar('url', $_POST['url_' . $key]);
if ($linkObj->getVar('url') != '') {
$icmsObj->storeUrlLinkObj($linkObj);
}
$icmsObj->setVar($key, $linkObj->getVar('urllinkid'));
break;
case XOBJ_DTYPE_FILE:
if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] == '') {
$fileObj = $icmsObj->getFileObj($key);
$fileObj->setVar('mid', $_POST['mid_' . $key]);
$fileObj->setVar('caption', $_POST['caption_' . $key]);
$fileObj->setVar('description', $_POST['desc_' . $key]);
$fileObj->setVar('url', preg_replace('|[\.]+\/|', './', $_POST['url_' . $key]));
if (!($fileObj->getVar('url') == '' && $fileObj->getVar('url') == '' && $fileObj->getVar('url') == '')) {
$res = $icmsObj->storeFileObj($fileObj);
if ($res) {
$icmsObj->setVar($key, $fileObj->getVar('fileid'));
} else {
$icmsObj->setErrors($fileObj->getErrors());
}
}
}
break;
case XOBJ_DTYPE_STIME:
case XOBJ_DTYPE_MTIME:
case XOBJ_DTYPE_LTIME:
if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
$value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
} elseif (filter_var($_POST[$key], FILTER_VALIDATE_INT) == $_POST[$key]) {
$value = (int)$_POST[$key];
} else {
$value = strtotime($_POST[$key]);
}
$icmsObj->setVar($key, $value);
break;
case XOBJ_DTYPE_URL:
if (isset($_POST[$key])) {
$icmsObj->setVar($key, filter_var($_POST[$key], FILTER_SANITIZE_URL));
}
break;
case XOBJ_DTYPE_ARRAY:
if (is_array($_POST[$key])) {
$icmsObj->setVar($key, serialize($_POST[$key]));
}
break;
default:
$icmsObj->setVar($key, $_POST[$key]);
break;
}
}
}
public function &doStoreFromDefaultForm(&$icmsObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page=false, $debug=false) {
$this->postDataToObject($icmsObj);
if ($icmsObj->isNew()) {
$redirect_msg = $created_success_msg;
} else {
$redirect_msg = $modified_success_msg;
}
$uploaderResult = true;
if (isset($_POST['icms_upload_image']) || isset($_POST['icms_upload_file'])) {
$uploaderObj = new icms_file_MediaUploadHandler($icmsObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
foreach ( $_FILES as $name=>$file_array) {
if (isset ($file_array['name']) && $file_array['name'] != "" && in_array(str_replace('upload_', '', $name), array_keys($icmsObj->vars))) {
if ($uploaderObj->fetchMedia($name)) {
$uploaderObj->setTargetFileName(time() . "_" . $uploaderObj->getMediaName());
if ($uploaderObj->upload()) {
$uploaderResult = $uploaderResult && true;
$related_field = str_replace('upload_', '', $name);
$uploadedArray[] = $related_field;
if ($icmsObj->vars[$related_field]['data_type'] == XOBJ_DTYPE_FILE) {
$object_fileurl = $icmsObj->getUploadDir();
$fileObj = $icmsObj->getFileObj($related_field);
$fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
$fileObj->setVar('mid', $_POST['mid_' . $related_field]);
$fileObj->setVar('caption', $_POST['caption_' . $related_field]);
$fileObj->setVar('description', $_POST['desc_' . $related_field]);
$icmsObj->storeFileObj($fileObj);
$icmsObj->setVar($related_field, $fileObj->getVar('fileid'));
} else {
$eventResult = $this->handler->executeEvent('beforeFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the beforeFileUnlink event");
$uploaderResult = $uploaderResult && false;
}
$old_file = $icmsObj->getUploadDir(true) . $icmsObj->getVar($related_field);
if (is_file($old_file) ) unlink($old_file);
$icmsObj->setVar($related_field, $uploaderObj->getSavedFileName());
$eventResult = $this->handler->executeEvent('afterFileUnlink', $icmsObj);
if (!$eventResult) {
$icmsObj->setErrors("An error occured during the afterFileUnlink event");
$uploaderResult = $uploaderResult && false;
}
}
} else {
$icmsObj->setErrors($uploaderObj->getErrors(false));
$uploaderResult = $uploaderResult && false;
}
} else {
$icmsObj->setErrors($uploaderObj->getErrors(false));
$uploaderResult = $uploaderResult && false;
}
}
}
}
if ($uploaderResult) {
if ($debug) {
$storeResult = $this->handler->insertD($icmsObj);
} else {
$storeResult = $this->handler->insert($icmsObj);
}
} else {
$storeResult = false;
}
if ($storeResult) {
if ($this->handler->getPermissions()) {
$icmspermissions_handler = new icms_ipf_permission_Handler($this->handler);
$icmspermissions_handler->storeAllPermissionsForId($icmsObj->id());
}
}
if ($redirect_page === null) {
return $icmsObj;
} else {
if (!$storeResult) {
redirect_header(icms::$urls['previouspage'], 3, _CO_ICMS_SAVE_ERROR . $icmsObj->getHtmlErrors());
} else {
$redirect_page = $redirect_page ? $redirect_page : icms_get_page_before_form();
redirect_header($redirect_page, 2, $redirect_msg);
}
}
}
public function &storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page=false, $debug=false, $x_param = false) {
$objectid = ( isset($_POST[$this->handler->keyName]) )
? (int) $_POST[$this->handler->keyName]
: 0;
if ($debug) {
if ($x_param) {
$icmsObj = $this->handler->getD($objectid, true, $x_param);
} else {
$icmsObj = $this->handler->getD($objectid);
}
} else {
if ($x_param) {
$icmsObj = $this->handler->get($objectid, true, false, false, $x_param);
} else {
$icmsObj = $this->handler->get($objectid);
}
}
if (is_subclass_of($this->handler, 'icmspersistablemlobjecthandler')) {
if ($icmsObj->isNew()) {
$icmsObj->stripMultilanguageFields();
$newObject =& $this->doStoreFromDefaultForm($icmsObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
unset($icmsObj);
$icmsObj = $this->handler->get($objectid);
$icmsObj->stripNonMultilanguageFields();
$icmsObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
$this->handler->changeTableNameForML();
$ret =& $this->doStoreFromDefaultForm($icmsObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
return $ret;
}
} else {
return $this->doStoreFromDefaultForm($icmsObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
}
}
public function &storeicms_ipf_ObjectD() {
return $this->storeicms_ipf_Object(true);
}
public function &storeicms_ipf_Object($debug=false, $xparam = false) {
$ret =& $this->storeFromDefaultForm('', '', null, $debug, $xparam);
return $ret;
}
public function handleObjectDeletion($confirm_msg = false, $op='del', $userSide=false) {
$objectid = (isset($_REQUEST[$this->handler->keyName])) ? (int) $_REQUEST[$this->handler->keyName] : 0;
$icmsObj = $this->handler->get($objectid);
if ($icmsObj->isNew()) {
redirect_header("javascript:history.go(-1)", 3, _CO_ICMS_NOT_SELECTED);
exit();
}
$confirm = ( isset($_POST['confirm']) ) ? $_POST['confirm'] : 0;
if ($confirm) {
if (!$this->handler->delete($icmsObj)) {
redirect_header($_POST['redirect_page'], 3, _CO_ICMS_DELETE_ERROR . $icmsObj->getHtmlErrors());
exit;
}
redirect_header($_POST['redirect_page'], 3, _CO_ICMS_DELETE_SUCCESS);
exit();
} else {
icms_cp_header();
if (!$confirm_msg) {
$confirm_msg = _CO_ICMS_DELETE_CONFIRM;
}
$hiddens = array(
'op' => $op,
$this->handler->keyName => $icmsObj->getVar($this->handler->keyName),
'confirm' => 1,
'redirect_page' => icms::$urls['previouspage']
);
if ($this->handler->_moduleName == 'system') {
$hiddens['fct'] = isset($_GET['fct']) ? $_GET['fct'] : false;
}
icms_core_Message::confirm($hiddens, xoops_getenv('SCRIPT_NAME'), sprintf($confirm_msg , $icmsObj->getVar($this->handler->identifierName)), _CO_ICMS_DELETE);
icms_cp_footer();
}
exit();
}
public function handleObjectDeletionFromUserSide($confirm_msg = false, $op='del') {
global $icmsTpl;
$objectid = ( isset($_REQUEST[$this->handler->keyName]) ) ? (int) ($_REQUEST[$this->handler->keyName]) : 0;
$icmsObj = $this->handler->get($objectid);
if ($icmsObj->isNew()) {
redirect_header("javascript:history.go(-1)", 3, _CO_ICMS_NOT_SELECTED);
exit();
}
$confirm = ( isset($_POST['confirm']) ) ? $_POST['confirm'] : 0;
if ($confirm) {
if (!$this->handler->delete($icmsObj)) {
redirect_header($_POST['redirect_page'], 3, _CO_ICMS_DELETE_ERROR . $icmsObj->getHtmlErrors());
exit;
}
redirect_header($_POST['redirect_page'], 3, _CO_ICMS_DELETE_SUCCESS);
exit();
} else {
if (!$confirm_msg) {
$confirm_msg = _CO_ICMS_DELETE_CONFIRM;
}
ob_start();
icms_core_Message::confirm(array(
'op' => $op,
$this->handler->keyName => $icmsObj->getVar($this->handler->keyName),
'confirm' => 1,
'redirect_page' => icms::$urls['previouspage']),
xoops_getenv('SCRIPT_NAME'),
sprintf($confirm_msg ,
$icmsObj->getVar($this->handler->identifierName)),
_CO_ICMS_DELETE
);
$icmspersistable_delete_confirm = ob_get_clean();
$icmsTpl->assign('icmspersistable_delete_confirm', $icmspersistable_delete_confirm);
}
}
public function getAdminViewItemLink($icmsObj, $onlyUrl=false, $withimage=false) {
$ret = $this->handler->_moduleUrl . "admin/"
. $this->handler->_page . "?op=view&"
. $this->handler->keyName . "="
. $icmsObj->getVar($this->handler->keyName);
if ($onlyUrl) {
return $ret;
} elseif ($withimage) {
return "<a href='" . $ret . "'>
<img src='" . ICMS_IMAGES_SET_URL
. "/actions/viewmag.png' style='vertical-align: middle;' alt='"
. _CO_ICMS_ADMIN_VIEW . "' title='"
. _CO_ICMS_ADMIN_VIEW . "'/></a>";
}
return "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
public function getItemLink(&$icmsObj, $onlyUrl=false) {
$seoMode = false;
$seoModuleName = $this->handler->_moduleName;
$seoIncludeId = true;
$ret = $this->handler->_moduleUrl . $this->handler->_page . "?" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
if (!$onlyUrl) {
$ret = "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
return $ret;
}
public function getViewItemLink($icmsObj, $onlyUrl=false, $withimage=true, $userSide=false) {
if ($this->handler->_moduleName != 'system') {
$admin_side = $userSide ? '' : 'admin/';
$ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . "?" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
} else {
$admin_side = '';
$ret = $this->handler->_moduleUrl . $admin_side . 'admin.php?fct='
. $this->handler->_itemname . "&op=view&"
. $this->handler->keyName . "="
. $icmsObj->getVar($this->handler->keyName);
}
if ($onlyUrl) {
return $ret;
} elseif ($withimage) {
return "<a href='" . $ret . "'>
<img src='" . ICMS_IMAGES_SET_URL . "/actions/viewmag.png' style='vertical-align: middle;' alt='"
. _PREVIEW . "' title='" . _PREVIEW . "'/></a>";
}
return "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
public function getEditLanguageLink($icmsObj, $onlyUrl=false, $withimage=true) {
$ret = $this->handler->_moduleUrl . "admin/"
. $this->handler->_page
. "?op=mod&" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName)
. "&language=" . $icmsObj->getVar('language');
if ($onlyUrl) {
return $ret;
} elseif ($withimage) {
return "<a href='" . $ret . "'>
<img src='" . ICMS_IMAGES_SET_URL . "/actions/wizard.png' style='vertical-align: middle;' alt='"
. _CO_ICMS_LANGUAGE_MODIFY . "' title='" . _CO_ICMS_LANGUAGE_MODIFY . "'/></a>";
}
return "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
public function getEditItemLink($icmsObj, $onlyUrl=false, $withimage=true, $userSide=false) {
if ($this->handler->_moduleName != 'system') {
$admin_side = $userSide ? '' : 'admin/';
$ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page
. "?op=mod&" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
} else {
$admin_side = '';
$ret = $this->handler->_moduleUrl . $admin_side
. 'admin.php?fct=' . $this->handler->_itemname
. "&op=mod&" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
}
if ($onlyUrl) {
return $ret;
} elseif ($withimage) {
return "<a href='" . $ret . "'>
<img src='" . ICMS_IMAGES_SET_URL . "/actions/edit.png' style='vertical-align: middle;' alt='"
. _CO_ICMS_MODIFY . "' title='" . _CO_ICMS_MODIFY . "'/></a>";
}
return "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
public function getDeleteItemLink($icmsObj, $onlyUrl=false, $withimage=true, $userSide=false) {
if ($this->handler->_moduleName != 'system') {
$admin_side = $userSide ? '' : 'admin/';
$ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page
. "?op=del&" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
} else {
$admin_side = '';
$ret = $this->handler->_moduleUrl . $admin_side
. 'admin.php?fct=' . $this->handler->_itemname
. "&op=del&" . $this->handler->keyName . "=" . $icmsObj->getVar($this->handler->keyName);
}
if ($onlyUrl) {
return $ret;
} elseif ($withimage) {
return "<a href='" . $ret . "'>
<img src='" . ICMS_IMAGES_SET_URL . "/actions/editdelete.png' style='vertical-align: middle;' alt='"
. _CO_ICMS_DELETE . "' title='" . _CO_ICMS_DELETE . "'/></a>";
}
return "<a href='" . $ret . "'>" . $icmsObj->getVar($this->handler->identifierName) . "</a>";
}
public function getPrintAndMailLink($icmsObj) {
global $icmsConfig;
$ret = '';
return $ret;
}
public function getModuleItemString() {
$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
return $ret;
}
}