Пример #1
0
 function remove_directory($directory, $empty = FALSE)
 {
     if (substr($directory, -1) == '/') {
         $directory = substr($directory, 0, -1);
     }
     if (!file_exists($directory) || !is_dir($directory)) {
         return FALSE;
     } elseif (!is_readable($directory)) {
         return FALSE;
     } else {
         $handle = opendir($directory);
         while (FALSE !== ($item = readdir($handle))) {
             if ($item != '.' && $item != '..') {
                 $path = $directory . '/' . $item;
                 if (is_dir($path)) {
                     remove_directory($path);
                 } else {
                     unlink($path);
                 }
             }
         }
         closedir($handle);
         if ($empty == FALSE) {
             if (!rmdir($directory)) {
                 return FALSE;
             }
         }
         return TRUE;
     }
 }
 function remove_directory($dir)
 {
     if ($handle = opendir("{$dir}")) {
         while (false !== ($item = readdir($handle))) {
             if ($item != "." && $item != "..") {
                 if (is_dir("{$dir}/{$item}")) {
                     remove_directory("{$dir}/{$item}");
                 } else {
                     unlink("{$dir}/{$item}");
                 }
             }
         }
         closedir($handle);
         rmdir($dir);
     }
 }
Пример #3
0
 function remove_directory($dir)
 {
     if (substr($dir, -1, 1) == "/") {
         $dir = substr($dir, 0, strlen($dir) - 1);
     }
     if ($handle = opendir("{$dir}")) {
         while (false !== ($item = readdir($handle))) {
             if ($item != "." && $item != "..") {
                 if (is_dir("{$dir}/{$item}")) {
                     remove_directory("{$dir}/{$item}");
                 } else {
                     unlink("{$dir}/{$item}");
                 }
             }
         }
         closedir($handle);
         rmdir($dir);
     }
 }
Пример #4
0
/**
* remove_directory
* Will recursively remove directories and clean up files in each directory.
*
* @param String $directory Name of directory to clean up and clear.
*
* @return Boolean Returns false if it can't remove a directory or a file. Returns true if it all worked ok.
*/
function remove_directory($directory='')
{
	$safe_mode = ini_get('safe_mode');

	if (!is_dir($directory)) {
		return true;
	}

	// need to use the '@' in case we can't open the directory
	// otherwise it still throws a notice.
	if (!$handle = @opendir($directory)) {
		return false;
	}

	while (($file = readdir($handle)) !== false) {
		if ($file == '.' || $file == '..') {
			continue;
		}

		$f = $directory . '/' . $file;
		if (is_dir($f)) {
			remove_directory($f);
			continue;
		}

		if (is_file($f)) {
			if (!unlink($f)) {
				closedir($handle);
				return false;
			}
		}
	}
	closedir($handle);

	if ($safe_mode) {
		$status = true;
	} else {
		$status = rmdir($directory);
	}
	return $status;
}
Пример #5
0
function remove_directory($path)
{
    $dir = @opendir($path);
    if ($dir === FALSE) {
        return false;
    }
    //remove all files and subdirectories in directory
    while ($file = readdir($dir)) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        if (is_dir($path . '/' . $file)) {
            remove_directory($path . '/' . $file);
        } else {
            @unlink($path . '/' . $file);
        }
    }
    //remove directory
    closedir($dir);
    rmdir($path);
    return true;
}
Пример #6
0
	/**
	* Delete
	* Delete a template from the database
	* This will also clean up after itself in case there are any attachments or images associated with the template.
	*
	* @param Int $templateid Templateid of the template to delete. If not passed in, it will delete 'this' template. We delete the template, then reset all class vars.
	*
	* @see remove_directory
	*
	* @return Boolean True if it deleted the template, false otherwise.
	*/
	function Delete($templateid=0)
	{
		if ($templateid == 0) {
			$templateid = $this->templateid;
		}

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "templates WHERE templateid='" . $templateid. "'";
		$result = $this->Db->Query($query);
		if (!$result) {
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		$template_dir = TEMP_DIRECTORY . '/templates/' . $templateid;
		remove_directory($template_dir);

		$this->templateid = 0;
		$this->name = '';
		$this->format = 'h';
		$this->active = 0;
		$this->SetBody('text', '');
		$this->SetBody('html', '');
		$this->ownerid = 0;
		return true;
	}
Пример #7
0
 /**
  * Call action (mark as fav, archive, delete, etc.)
  */
 public function action($action, Url $url, $id = 0, $import = FALSE, $autoclose = FALSE, $tags = null)
 {
     switch ($action) {
         case 'add':
             $content = Tools::getPageContent($url);
             $title = $content['rss']['channel']['item']['title'] != '' ? $content['rss']['channel']['item']['title'] : _('Untitled');
             $body = $content['rss']['channel']['item']['description'];
             // clean content from prevent xss attack
             $purifier = $this->getPurifier();
             $title = $purifier->purify($title);
             $body = $purifier->purify($body);
             //search for possible duplicate
             $duplicate = NULL;
             $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId());
             $last_id = $this->store->add($url->getUrl(), $title, $body, $this->user->getId());
             if ($last_id) {
                 Tools::logm('add link ' . $url->getUrl());
                 if (DOWNLOAD_PICTURES) {
                     $content = filtre_picture($body, $url->getUrl(), $last_id);
                     Tools::logm('updating content article');
                     $this->store->updateContent($last_id, $content, $this->user->getId());
                 }
                 if ($duplicate != NULL) {
                     // duplicate exists, so, older entry needs to be deleted (as new entry should go to the top of list), BUT favorite mark and tags should be preserved
                     Tools::logm('link ' . $url->getUrl() . ' is a duplicate');
                     // 1) - preserve tags and favorite, then drop old entry
                     $this->store->reassignTags($duplicate['id'], $last_id);
                     if ($duplicate['is_fav']) {
                         $this->store->favoriteById($last_id, $this->user->getId());
                     }
                     if ($this->store->deleteById($duplicate['id'], $this->user->getId())) {
                         Tools::logm('previous link ' . $url->getUrl() . ' entry deleted');
                     }
                 }
                 $this->messages->add('s', _('the link has been added successfully'));
             } else {
                 $this->messages->add('e', _('error during insertion : the link wasn\'t added'));
                 Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl());
             }
             if ($autoclose == TRUE) {
                 Tools::redirect('?view=home');
             } else {
                 Tools::redirect('?view=home&closewin=true');
             }
             break;
         case 'delete':
             $msg = 'delete link #' . $id;
             if ($this->store->deleteById($id, $this->user->getId())) {
                 if (DOWNLOAD_PICTURES) {
                     remove_directory(ABS_PATH . $id);
                 }
                 $this->messages->add('s', _('the link has been deleted successfully'));
             } else {
                 $this->messages->add('e', _('the link wasn\'t deleted'));
                 $msg = 'error : can\'t delete link #' . $id;
             }
             Tools::logm($msg);
             Tools::redirect('?');
             break;
         case 'toggle_fav':
             $this->store->favoriteById($id, $this->user->getId());
             Tools::logm('mark as favorite link #' . $id);
             if (Tools::isAjaxRequest()) {
                 echo 1;
                 exit;
             } else {
                 Tools::redirect();
             }
             break;
         case 'toggle_archive':
             $this->store->archiveById($id, $this->user->getId());
             Tools::logm('archive link #' . $id);
             if (Tools::isAjaxRequest()) {
                 echo 1;
                 exit;
             } else {
                 Tools::redirect();
             }
             break;
         case 'archive_all':
             $this->store->archiveAll($this->user->getId());
             Tools::logm('archive all links');
             Tools::redirect();
             break;
         case 'add_tag':
             if (isset($_GET['search'])) {
                 //when we want to apply a tag to a search
                 $tags = array($_GET['search']);
                 $allentry_ids = $this->store->search($tags[0], $this->user->getId());
                 $entry_ids = array();
                 foreach ($allentry_ids as $eachentry) {
                     $entry_ids[] = $eachentry[0];
                 }
             } else {
                 //add a tag to a single article
                 $tags = explode(',', $_POST['value']);
                 $entry_ids = array($_POST['entry_id']);
             }
             foreach ($entry_ids as $entry_id) {
                 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId());
                 if (!$entry) {
                     $this->messages->add('e', _('Article not found!'));
                     Tools::logm('error : article not found');
                     Tools::redirect();
                 }
                 //get all already set tags to preven duplicates
                 $already_set_tags = array();
                 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
                 foreach ($entry_tags as $tag) {
                     $already_set_tags[] = $tag['value'];
                 }
                 foreach ($tags as $key => $tag_value) {
                     $value = trim($tag_value);
                     if ($value && !in_array($value, $already_set_tags)) {
                         $tag = $this->store->retrieveTagByValue($value);
                         if (is_null($tag)) {
                             # we create the tag
                             $tag = $this->store->createTag($value);
                             $sequence = '';
                             if (STORAGE == 'postgres') {
                                 $sequence = 'tags_id_seq';
                             }
                             $tag_id = $this->store->getLastId($sequence);
                         } else {
                             $tag_id = $tag['id'];
                         }
                         # we assign the tag to the article
                         $this->store->setTagToEntry($tag_id, $entry_id);
                     }
                 }
             }
             $this->messages->add('s', _('The tag has been applied successfully'));
             Tools::logm('The tag has been applied successfully');
             Tools::redirect();
             break;
         case 'remove_tag':
             $tag_id = $_GET['tag_id'];
             $entry = $this->store->retrieveOneById($id, $this->user->getId());
             if (!$entry) {
                 $this->messages->add('e', _('Article not found!'));
                 Tools::logm('error : article not found');
                 Tools::redirect();
             }
             $this->store->removeTagForEntry($id, $tag_id);
             Tools::logm('tag entry deleted');
             if ($this->store->cleanUnusedTag($tag_id)) {
                 Tools::logm('tag deleted');
             }
             $this->messages->add('s', _('The tag has been successfully deleted'));
             Tools::redirect();
             break;
         default:
             break;
     }
 }
Пример #8
0
/**
 * Suppression du répertoire d'images
 */
function remove_directory($directory)
{
    if (is_dir($directory)) {
        $files = array_diff(scandir($directory), array('.', '..'));
        foreach ($files as $file) {
            is_dir("{$directory}/{$file}") ? remove_directory("{$directory}/{$file}") : unlink("{$directory}/{$file}");
        }
        return rmdir($directory);
    }
}
Пример #9
0
     pre_configure_site();
     if (INSTALL_SEO_URLS == 1) {
         $contents = '#-MS- SEO-G Added' . "\n" . 'Options +FollowSymLinks' . "\n" . 'RewriteEngine On' . "\n" . 'RewriteBase ' . DIR_WS_HTTP_CATALOG . "\n\n" . '# Note whatever extension you use it should match the SEO-G configuration -> extension on the admin end even if its blank' . "\n" . '# Also the separators defined in the SEO-G for the various entities should be included in the rule here.' . "\n\n" . '# Rules for extensionless URLs' . "\n" . '# 1. Using a trailing slash' . "\n" . '#RewriteRule ^(.*)/$ root.php?$1&%{QUERY_STRING}' . "\n\n" . '# 2. Not using a trailing slash links with alphanumeric characters and hyphens' . "\n" . '#RewriteRule ^([a-z0-9_-]+)$ root.php?$1&%{QUERY_STRING}' . "\n\n" . '# Rules for URLs with extensions' . "\n" . '#RewriteRule ^(.*).asp$ root.php?$1.asp&%{QUERY_STRING}' . "\n" . '#RewriteRule ^(.*).(htm|html|asp|jsp|aspx)$ root.php?$1.*&%{QUERY_STRING}' . "\n\n" . '# Current Rules to support multiple extensions' . "\n" . '#RewriteRule ^([a-z0-9_-]+)$ root.php?$1&%{QUERY_STRING}' . "\n" . 'RewriteRule ^([/a-z0-9_-]+)$ root.php?$1&%{QUERY_STRING}' . "\n" . 'RewriteRule ^(.*)/$ root.php?$1&%{QUERY_STRING}' . "\n" . 'RewriteRule ^(.*).(htm|html|asp|jsp|aspx)$ root.php?$1.*&%{QUERY_STRING}' . "\n" . '#-MS- SEO-G Added EOM' . "\n";
         $result = write_contents('.htaccess', $contents);
         if (!$result) {
             $errors_array[] = ERROR_GLOBAL_WRITE_HTACCESS;
         }
         $contents = '#-MS- Disable SEO-G on admin folder' . "\n" . 'Options +FollowSymLinks' . "\n" . 'RewriteEngine On' . "\n" . 'RewriteBase ' . DIR_WS_HTTP_CATALOG . 'admin/' . "\n" . 'RewriteRule ^(.*)$ $1 [L]' . "\n" . '#-MS- SEO-G Added EOM' . "\n";
         chdir(DIR_FS_CATALOG . 'admin/');
         $result = write_contents('.htaccess', $contents);
         if (!$result) {
             $errors_array[] = ERROR_GLOBAL_WRITE_HTACCESS;
         }
     }
     chdir($current_dir);
     remove_directory($current_dir);
     chdir(DIR_FS_CATALOG);
     break;
 case 'license_agreement':
     $amend = '';
     if (!read_contents(FILE_LICENSE, $contents) || !read_contents(FILE_LICENSE_AMENDMENT, $amend)) {
         redirect($_SERVER['SCRIPT_NAME']);
     }
     if (!isset($_POST['license'])) {
         $error_string = ERROR_GLOBAL_LICENSE_AGREE;
         redirect($_SERVER['SCRIPT_NAME'] . '?error_string=' . $error_string);
     }
     redirect($_SERVER['SCRIPT_NAME'] . '?action=server_detect');
     break;
 default:
     if (!read_contents(FILE_LICENSE, $contents) || !read_contents(FILE_LICENSE_AMENDMENT, $amend)) {
Пример #10
0
/**
* remove_directory
* Will recursively remove directories and clean up files in each directory.
*
* @param directory Name of directory to clean up and clear.
*
* @return boolean Returns false if it can't remove a directory or a file. Returns true if it all worked ok.
*/
function remove_directory($directory = '')
{
    if (!is_dir($directory)) {
        return true;
    }
    if (!($handle = opendir($directory))) {
        return false;
    }
    while (($file = readdir($handle)) !== false) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $f = $directory . '/' . $file;
        if (is_dir($f)) {
            remove_directory($directory . '/' . $f);
        }
        if (is_file($f)) {
            if (!unlink($f)) {
                closedir($handle);
                return false;
            }
        }
    }
    closedir($handle);
    return true;
}
Пример #11
0
	/**
	* Delete
	* Delete an autoresponder from the database. Also deletes the queue associated with it.
	*
	* @param Int $autoresponderid Autoresponderid of the autoresponder to delete. If not passed in, it will delete 'this' autoresponder. We delete the autoresponder, then reset all class vars.
	* @param Int $userid The user doing the deleting of the autoresponder. This is so the stats api can "hide" autoresponder stats.
	*
	* @see Stats_API::HideStats
	* @see ClearQueue
	*
	* @return Boolean True if it deleted the autoresponder, false otherwise.
	*
	*/
	function Delete($autoresponderid=0, $userid=0)
	{
		if ($autoresponderid == 0) {
			$autoresponderid = $this->autoresponderid;
		}

		$this->Load($autoresponderid);

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "autoresponders WHERE autoresponderid='" . $autoresponderid. "'";
		$result = $this->Db->Query($query);
		if (!$result) {
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		$this->ClearQueue($this->queueid, 'autoresponder');

		$autoresponder_dir = TEMP_DIRECTORY . '/autoresponders/' . $autoresponderid;
		remove_directory($autoresponder_dir);

		$this->autoresponderid = 0;
		$this->name = '';
		$this->format = 'h';
		$this->hoursaftersubscription = 0;
		$this->queueid = 0;
		$this->archive = 0;
		$this->SetBody('text', '');
		$this->SetBody('html', '');
		$this->ownerid = 0;
		$this->autorespondersize = 0;

		$stats = array();
		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_autoresponders WHERE autoresponderid='" . $autoresponderid . "'";
		$result = $this->Db->Query($query);
		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		// clean up stats
		if (!class_exists('stats_api', false)) {
			require_once(dirname(__FILE__) . '/stats.php');
		}

		$stats_api = new Stats_API();

		$stats_api->HideStats($stats, 'autoresponder', $userid);

		return true;
	}
Пример #12
0
    public function publish_student()
    {
        $base_url_all = base_url('studentelements');
        $this->load->helper('file');
        $this->load->helper('directory');
        $params = array('hostname' => $this->_hostName, 'username' => $this->_userName, 'password' => $this->_password);
        $this->load->library('CPanelAddons', $params, 'CPanelAddons');
        $remote_url = '';
        //        $this->load->library('CPanelAddons');
        if (!isset($_POST['siteID'])) {
            $return = array();
            $temp = array();
            $temp['header'] = $this->lang->line('sites_publish_error1_heading');
            $temp['content'] = $this->lang->line('sites_publish_error1_message');
            $return['responseCode'] = 0;
            $return['responseHTML'] = $this->load->view('partials/error', array('data' => $temp), true);
            die(json_encode($return));
        }
        //some error prevention first
        //siteID ok?
        $siteDetails = $this->sitemodel->getSite($_POST['siteID']);
        if ($siteDetails == false) {
            $return = array();
            $temp = array();
            $temp['header'] = $this->lang->line('sites_publish_error1_heading');
            $temp['content'] = $this->lang->line('sites_publish_error1_message');
            $return['responseCode'] = 0;
            $return['responseHTML'] = $this->load->view('partials/error', array('data' => $temp), true);
            die(json_encode($return));
        }
        $userID = $siteDetails['site']->users_id;
        if ($siteDetails['site']->domain_ok != 1 || !isset($siteDetails['site']->domain)) {
            $return = array();
            $temp = array();
            $temp['header'] = $this->lang->line('sites_publish_error3_heading');
            $temp['content'] = $this->lang->line('sites_publish_error3_message');
            $return['responseCode'] = 0;
            $return['responseHTML'] = $this->load->view('partials/error', array('data' => $temp), true);
            die(json_encode($return));
        }
        $path = 'public_html/' . $siteDetails['site']->domain;
        $absPath = './' . $siteDetails['site']->domain;
        if (!is_dir($absPath) && $siteDetails['site']->domain != '') {
            mkdir($absPath, 0777);
        }
        //do we have anythin to publish at all?
        //		if( !isset( $_POST['xpages'] ) || $_POST['xpages'] == '' ) {
        if (!isset($_POST['item']) || $_POST['item'] == '') {
            //nothing to upload
            $return = array();
            $temp = array();
            $temp['header'] = $this->lang->line('sites_publish_error2_heading');
            $temp['content'] = $this->lang->line('sites_publish_error2_message');
            $return['responseCode'] = 0;
            $return['responseHTML'] = $this->load->view('partials/error', array('data' => $temp), true);
            die(json_encode($return));
        }
        if (isset($siteDetails['site']->url_option) && $siteDetails['site']->url_option != 'freeUrl' && $siteDetails['site']->domain_publish == 0) {
            $result = $this->CPanelAddons->add($siteDetails['site']->domain, $path);
            if (isset($result['cpanelresult']['data'][0]['result']) && trim($result['cpanelresult']['data'][0]['result']) == '0') {
                $return = array();
                $temp = array();
                $temp['header'] = $this->lang->line('sites_publish_error2_heading');
                $temp['content'] = "cPanel: " . $result['cpanelresult']['data'][0]['reason'];
                $return['responseCode'] = 0;
                $return['responseHTML'] = $this->load->view('partials/error', array('data' => $temp), true);
                die(json_encode($return));
            } else {
                $this->users_domains_model->domain_publish($_POST['siteID']);
            }
        }
        if ($siteDetails['site']->url_option == 'freeUrl') {
            $remote_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $siteDetails['site']->domain;
        } else {
            $remote_url = 'http://' . $siteDetails['site']->domain;
        }
        //		foreach( $_POST['xpages'] as $page=>$content ) {
        $page = $_POST['item'];
        $content = $_POST['pageContent'];
        //get page meta
        $pageMeta = $this->pagemodel->getSinglePage($_POST['siteID'], $page);
        $meta = '<title>' . $siteDetails['site']->sites_name . '</title>' . "\r\n";
        $header_includes = "";
        if (!empty($pageMeta->pages_title)) {
            //insert title, meta keywords and meta description
            $meta .= '<meta name="description" content="' . $pageMeta->pages_meta_description . '">' . "\r\n";
            $meta .= '<meta name="keywords" content="' . $pageMeta->pages_meta_keywords . '">';
            $header_includes .= $pageMeta->pages_header_includes;
            $pageContent = str_replace('<!--pageMeta-->', $meta, $content);
            //insert header includes;
            $pageContent = str_replace("<!--headerIncludes-->", $header_includes, $pageContent);
        } else {
            $pageContent = str_replace('<!--pageMeta-->', $meta, $content);
            $pageContent = str_replace("<!--headerIncludes-->", $header_includes, $pageContent);
        }
        //remove video cover
        $pageContent = str_replace('<div style="" data-selector=".frameCover" class="frameCover" data-type="video"></div>', "", $pageContent);
        $pageContent = str_replace('<div style="margin: 0px;" data-selector=".frameCover" class="frameCover" data-type="video"></div>', "", $pageContent);
        $pageContent = str_replace('<div data-selector=".frameCover" class="frameCover" data-type="video"></div>', "", $pageContent);
        $pageContent = str_replace('<div data-type="video" class="frameCover" data-selector=".frameCover"></div>', "", $pageContent);
        $pageContent = str_replace('class="frameCover"', "", $pageContent);
        /* STUDENT SECTION NEEDED */
        $valUrl = base_url();
        $accUrl = site_url('login/checkProfileLogin/' . $this->encrypt->encode($_POST['siteID']));
        $script = <<<'EOS'
				<?PHP 
                session_start();
                if(!isset($_SESSION) || session_id() == "") { 
					if(isset($_REQUEST['sessid']) && $_REQUEST['sessid']!="" ) {
						list($sid, $ext) = explode('-', $_REQUEST['sessid']);
						session_id($sid);
					}
				} 
			?>
EOS;
        $sessionSet = <<<'EOD'
		<?PHP
EOD;
        $sessionSet .= '  $sess = isset($_SESSION["extids"]["' . base64_encode($siteDetails['site']->site_id) . '"])?$_SESSION["extids"]["' . base64_encode($siteDetails['site']->site_id) . '"]:"";';
        $sessionSet .= <<<'EOD'

			if(is_array($_SESSION) && count($_SESSION)>0 && isset($sess)) {
				?>
				<input type="hidden" class="myid" name="myid" value="<?PHP echo base64_encode($sess); ?>">
				<?PHP
			}
			else {
				?>
				<input type="hidden" class="myid" name="myid" value="">
				<?PHP
				
			}
		?>
EOD;
        $pageContent = str_replace("<!-- password check url -->", '<input type="hidden" class="siteurl" name="siteurl" value="' . $valUrl . '">', $pageContent);
        $pageContent = str_replace("<!-- site url -->", '<input type="hidden" class="siteaccess" name="siteaccess" value="' . $accUrl . '">', $pageContent);
        $pageContent = str_replace("<!-- session -->", $script, $pageContent);
        $pageContent = str_replace("<!-- password protection on-->", '<input type="hidden" class="hiddenpassword" name="haspassword" value="' . $siteDetails['site']->has_password . '">', $pageContent);
        $pageContent = str_replace("<!-- session variable -->", $sessionSet, $pageContent);
        $pageContent = str_replace("<!-- site id -->", '<input type="hidden" class="siteId" name="siteId" value="' . base64_encode($siteDetails['site']->site_id) . '">', $pageContent);
        /* STUDENT SECTION NEEDED ENDS */
        $pageContent = str_replace("<!-- site contact url div -->", '<div id="contact-url" data-content="' . site_url('login/site_contact/' . $this->encrypt->encode($_POST['siteID'])) . '"></div>', $pageContent);
        $pageContent = str_replace("<!-- site counter url div -->", '<div id="counter-url" data-content="' . site_url('login/visitor_counter/' . $this->encrypt->encode($_POST['siteID'])) . '"></div>', $pageContent);
        $pageContent = str_replace("<!-- site url div -->", '<div id="site-url" data-content="' . $base_url_all . '"></div>', $pageContent);
        $pageContent = str_replace("<!-- page id div -->", '<div id="page-id" data-content="' . $pageMeta->pages_id . '"></div>', $pageContent);
        $pageContent = str_replace("<!-- page url div -->", '<div id="page-url" data-content="' . $remote_url . '/' . $page . '.php"></div>', $pageContent);
        if (!stristr($pageContent, '<link href="' . base_url('elements'))) {
            $pageContent = str_replace('<link href="', '<link href="' . $base_url_all . '/', $pageContent);
        }
        if (stristr($pageContent, '<link href="' . $base_url_all . '/https://')) {
            $pageContent = str_replace('<link href="' . $base_url_all . '/https://', '<link href="https://', $pageContent);
        }
        if (!stristr($pageContent, '<script src="' . $base_url_all . '/js')) {
            $pageContent = str_replace('<script src="js', '<script src="' . $base_url_all . '/js', $pageContent);
        }
        if (stristr($pageContent, 'src="' . $base_url_all . '/https://')) {
            $pageContent = str_replace('src="' . $base_url_all . '/https://', 'src="https://', $pageContent);
        }
        if (stristr($pageContent, '<script src="' . $base_url_all . '/http://')) {
            $pageContent = str_replace('<script src="' . $base_url_all . '/http://', '<script src="http://', $pageContent);
        }
        if (strstr($pageContent, 'src="/elements/images')) {
            $pageContent = str_replace('src="/elements/images', 'src="' . $base_url_all . '/images', $pageContent);
        }
        if (strstr($pageContent, 'url(&quot;/elements/images')) {
            $pageContent = str_replace('url(&quot;/elements/images', 'url(&quot;' . site_url('elements/images'), $pageContent);
        }
        if (strstr($pageContent, 'url(&quot;/studentelements/images')) {
            $pageContent = str_replace('url(&quot;/studentelements/images', 'url(&quot;' . site_url('studentelements/images'), $pageContent);
        }
        if (strstr($pageContent, 'src="/studentelements/images')) {
            $pageContent = str_replace('src="/studentelements/images', 'src="' . $base_url_all . '/images', $pageContent);
        }
        if (stristr($pageContent, 'href="scripts')) {
            $pageContent = str_replace('href="scripts', 'href="' . $base_url_all . '/scripts', $pageContent);
        }
        if (stristr($pageContent, '<script src="scripts')) {
            $pageContent = str_replace('<script src="scripts', '<script src="' . $base_url_all . '/scripts', $pageContent);
        }
        if (stristr($pageContent, 'href="images')) {
            $pageContent = str_replace('href="images', 'href="' . $base_url_all . '/images', $pageContent);
        }
        if (stristr($pageContent, 'src="./images')) {
            $pageContent = str_replace('src="./images', 'src="' . $base_url_all . '/images', $pageContent);
        }
        if (stristr($pageContent, 'src="../elements/scripts')) {
            $pageContent = str_replace('src="../elements/scripts', 'src="' . site_url('/elements/scripts'), $pageContent);
        }
        if (stristr($pageContent, 'href="./images')) {
            $pageContent = str_replace('href="./images', 'href="' . $base_url_all . '/images', $pageContent);
        }
        write_file($absPath . '/' . $page . ".php", trim($pageContent));
        //		}
        isset($userID) && $userID != '' ? remove_directory('./temp/' . $userID) : '';
        $this->sitemodel->publish($_POST['siteID'], base_url() . $siteDetails['site']->domain);
        if ($siteDetails['site']->url_option == 'freeUrl') {
            $this->users_domains_model->domain_publish($_POST['siteID']);
        }
        //all went well
        $return = array();
        $return['responseCode'] = 1;
        die(json_encode($return));
    }
Пример #13
0
function saveOds($obj, $file)
{
    $charset = ini_get('default_charset');
    ini_set('default_charset', 'UTF-8');
    $tmp = get_tmp_dir();
    $uid = uniqid();
    mkdir($tmp . '/' . $uid);
    file_put_contents($tmp . '/' . $uid . '/content.xml', $obj->array2ods());
    file_put_contents($tmp . '/' . $uid . '/mimetype', 'application/vnd.oasis.opendocument.spreadsheet');
    file_put_contents($tmp . '/' . $uid . '/meta.xml', $obj->getMeta('pt-BR'));
    file_put_contents($tmp . '/' . $uid . '/styles.xml', $obj->getStyle());
    file_put_contents($tmp . '/' . $uid . '/settings.xml', $obj->getSettings());
    mkdir($tmp . '/' . $uid . '/META-INF/');
    mkdir($tmp . '/' . $uid . '/Configurations2/');
    mkdir($tmp . '/' . $uid . '/Configurations2/acceleator/');
    mkdir($tmp . '/' . $uid . '/Configurations2/images/');
    mkdir($tmp . '/' . $uid . '/Configurations2/popupmenu/');
    mkdir($tmp . '/' . $uid . '/Configurations2/statusbar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/floater/');
    mkdir($tmp . '/' . $uid . '/Configurations2/menubar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/progressbar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/toolbar/');
    file_put_contents($tmp . '/' . $uid . '/META-INF/manifest.xml', $obj->getManifest());
    $ziper = new zipfile();
    $ziper->addFiles($tmp . '/' . $uid, array('META-INF', 'Configurations2', 'content.xml', 'meta.xml', 'mimetype', 'settings.xml', 'styles.xml'));
    $ziper->output($file);
    remove_directory($tmp . '/' . $uid);
    ini_set('default_charset', $charset);
}
Пример #14
0
     }
 } else {
     if ($op == "gallerycat_del") {
         //////////////////////////////////////////// ¡Ã³Õź Form
         if (CheckLevel($admin_user, $op)) {
             $db->connectdb(DB_NAME, DB_USERNAME, DB_PASSWORD);
             $res['gallery'] = $db->select_query("SELECT * FROM " . TB_GALLERY_CAT . " where id='" . $_GET['id'] . "' ");
             $arr['gallery'] = $db->fetch($res['gallery']);
             $CAT = $arr['gallery']['post_date'];
             $res['cat'] = $db->select_query("SELECT * FROM " . TB_GALLERY . " WHERE category='" . $_GET['id'] . "' ");
             while ($arr['cat'] = $db->fetch($res['cat'])) {
                 $db->del(TB_GALLERY, " category='" . $arr['gallery']['id'] . "' ");
                 $db->del(TB_GALLERY_COMMENT, " gallery_id='" . $arr['cat']['id'] . "' ");
             }
             $galdir = "images/gallery/gal_" . $CAT . "";
             remove_directory($galdir);
             $db->del(TB_GALLERY_CAT, " id='" . $_GET['id'] . "' ");
             $db->closedb();
             $ProcessOutput = "<BR><BR>";
             $ProcessOutput .= "<CENTER><A HREF=\"?name=admin&file=main\"><IMG SRC=\"images/icon/login-welcome.gif\" BORDER=\"0\"></A><BR><BR>";
             $ProcessOutput .= "<FONT COLOR=\"#336600\"><B>" . _ADMIN_GALLERY_MESSAGE_DEL_CAT . "</B></FONT><BR><BR>";
             $ProcessOutput .= "<A HREF=\"?name=admin&file=gallery\"><B>" . _ADMIN_GALLERY_MESSAGE_GOBACK . "</B></A>";
             $ProcessOutput .= "</CENTER>";
             $ProcessOutput .= "<BR><BR>";
         } else {
             //¡Ã³ÕäÁè¼èÒ¹
             $ProcessOutput = $PermissionFalse;
         }
         echo $ProcessOutput;
     }
 }
Пример #15
0
function download_template_repo(&$output, $template, $childpath = false)
{
    # Creating the zip directory for the download
    $zip_file = tempnam('/tmp', 'REPODL');
    $zip_resource = fopen($zip_file, "w");
    # Logging
    $output[] = ' - Starting download of template repo "' . $template . '"<br />';
    # Loading the master branch from github
    $repo_url = 'https://github.com/nuQuery-Templates/' . $template . '/archive/master.zip';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $repo_url);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_FILE, $zip_resource);
    $success = curl_exec($ch);
    curl_close($ch);
    # Error downloading
    if (!$success) {
        $output[] = ' - Error downloading repo : ' . curl_error($ch) . '<br />';
        return false;
    } else {
        # Logging
        $output[] = ' - Download complete, unzipping.<br />';
        # Extracting the zip
        $zip = new ZipArchive();
        $save_path = __DIR__ . '/_installed/';
        mkdir($save_path);
        if ($zip->open($zip_file) != "true") {
            $output[] = ' - Unable to open the Zip File';
            return false;
        }
        $zip->extractTo($save_path);
        $zip->close();
        # Removing zip
        unlink($zip_file);
        # Moving directories into root
        if ($childpath !== false) {
            move_directory($save_path . $template . '-master/', $childpath . '/');
            remove_directory($save_path . $template . '-master');
        } else {
            rename($save_path . $template . '-master', __DIR__ . '/' . $template);
        }
        # Removing install directory
        remove_directory($save_path);
        # Logging
        $output[] = ' - Install of template "' . $template . '" complete.<br />';
    }
    # Success
    return true;
}
Пример #16
0
function del_user_dir($edogyt44 = 0)
{
	$vomawoh8 = (create_user_dir(0, 2) === true);
	if (!$vomawoh8) {
		GetFlashMessages();
	}
	if (!is_array($edogyt44) && $edogyt44 > 0) {
		remove_directory(TEMP_DIRECTORY . "/user/" . $edogyt44);
	}
	return true;
}
Пример #17
0
function remove_directory($dir)
{
    if ($handle = opendir("{$dir}")) {
        while (false !== ($item = readdir($handle))) {
            if ($item != "." && $item != "..") {
                if (is_dir("{$dir}/{$item}")) {
                    remove_directory("{$dir}/{$item}");
                } else {
                    unlink("{$dir}/{$item}");
                    //      echo " removing $dir/$item<br>\n";
                }
            }
        }
        closedir($handle);
        rmdir($dir);
        //    echo "removing $dir<br>\n";
    }
    function upimg($img, $imglocate)
    {
        if ($img['name'] != '') {
            $fileupload1 = $img['tmp_name'];
            $g_img = explode(".", $img['name']);
            $file_up = TIMESTAMP . "." . $g_img[1];
            // à»ÅÕ蹪×èÍä¿ÅìäËÁè à»ç¹µÑÇàÅ¢
            if ($fileupload1) {
                $array_last = explode(".", $file_up);
                $c = count($array_last) - 1;
                $lastname = strtolower($array_last[$c]);
                @copy($fileupload1, $imglocate . $file_up);
            }
        }
        return $file_up;
        // Ê觡ÅѺª×èÍä¿Åì
    }
}
Пример #18
0
    echo "<h1>Comand Line Interface Only!</h1>";
    die;
}
require_once 'include/check_version.php';
require_once 'PHP-Parser/lib/bootstrap.php';
require_once 'include/classes/config.php';
require_once 'include/classes/scrambler.php';
require_once 'include/classes/parser_extensions/my_pretty_printer.php';
require_once 'include/classes/parser_extensions/my_node_visitor.php';
require_once 'include/functions.php';
include 'include/retrieve_config_and_arguments.php';
if ($clean_mode && file_exists("{$target_directory}/yakpro-po/.yakpro-po-directory")) {
    if (!$conf->silent) {
        fprintf(STDERR, "Info:\tRemoving directory\t= [%s]%s", "{$target_directory}/yakpro-po", PHP_EOL);
    }
    remove_directory("{$target_directory}/yakpro-po");
    exit;
}
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative());
// $parser = new PhpParser\Parser(new PhpParser\Lexer);
$traverser = new PhpParser\NodeTraverser();
if ($conf->obfuscate_string_literal) {
    $prettyPrinter = new myPrettyprinter();
} else {
    $prettyPrinter = new PhpParser\PrettyPrinter\Standard();
}
$t_scrambler = array();
foreach (array('variable', 'function', 'method', 'property', 'class', 'class_constant', 'constant', 'namespace', 'label') as $dummy => $scramble_what) {
    $t_scrambler[$scramble_what] = new Scrambler($scramble_what, $conf, $process_mode == 'directory' ? $target_directory : null);
}
$traverser->addVisitor(new MyNodeVisitor());
Пример #19
0
	/**
	* MoveFiles
	* Moves uploaded images from temporary storage under a user's id - to it's final location - under the type and it's id. Eg newsletter/1.
	*
	* @param String $destination The destination (eg newsletter or template).
	* @param Int $id The destinations id.
	*
	* @see CreateDirectory
	* @see list_files
	*
	* @return Boolean Returns false if it can't create the paths or it can't copy the necessary files. Returns true if everything worked ok.
	*/
	function MoveFiles($destination=false, $id=0)
	{
		if (!$destination) {return false;}

                if($id <= 0){ return false; }
                
                $user = IEM::userGetCurrent();
                
                $tempid = $user->userid . "_tmp";
                
		$destinationdir = TEMP_DIRECTORY . '/' . $destination . '/' . $id;
		$tempdir = TEMP_DIRECTORY . '/' . $destination . '/' . $tempid;

                if(!file_exists($destinationdir)){
                    $createdir = CreateDirectory($destinationdir,TEMP_DIRECTORY,0777);
                    if (!$createdir) {return false;}
                }
		//Get files from the 'temporary' folder, /destination/userid_tmp/, and move them to the final location
                if(CopyDirectory($tempdir, $destinationdir)){remove_directory($tempdir);}
		
		return true;
	}
Пример #20
0
/**
* recursively removes a directory and all its content
*
* @param string $path the directory's full path
* @return NULL
*/
function rrmdir($path)
{
    $dir = dir($path);
    while (($entry = $dir->read()) !== FALSE) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        if (is_file($path . $entry)) {
            @unlink($path . $entry);
        } else {
            remove_directory($path . $entry . '/');
        }
    }
    $dir->close();
    @rmdir($path);
    return NULL;
}
Пример #21
0
 public function remove_directory($dir)
 {
     if ($handle = opendir("{$dir}")) {
         while (false !== ($item = readdir($handle))) {
             if ($item != "." && $item != "..") {
                 if (is_dir("{$dir}/{$item}")) {
                     remove_directory("{$dir}/{$item}");
                 } else {
                     unlink("{$dir}/{$item}");
                 }
             }
         }
         //closedir($handle);
         rmdir($dir);
         // echo"removing $dir<br>\n";
     }
 }
Пример #22
0
function plugin_qhmsetting_remove_dir($dir, $remain_dir = false)
{
    if ($handle = opendir("{$dir}")) {
        while (false !== ($item = readdir($handle))) {
            if ($item != "." && $item != "..") {
                if (is_dir("{$dir}/{$item}")) {
                    remove_directory("{$dir}/{$item}");
                } else {
                    unlink("{$dir}/{$item}");
                }
            }
        }
        closedir($handle);
        if (!$remain_dir) {
            if (is_link($dir)) {
                unlink($dir);
            } else {
                rmdir($dir);
            }
        }
    }
}
 function move_directory($directory, $destination)
 {
     return copy_directory($directory, $destination) | remove_directory($directory);
 }
	/**
	* Process
	* Takes the appropriate action based on the action and user permissions
	*
	* @see GetUser
	* @see User_API::HasAccess
	* @see PrintHeader
	* @see PrintFooter
	*
	* @return Void Doesn't return anything. Takes the appropriate action.
	*/
	function Process()
	{
		$GLOBALS['Message'] = '';

		$action = (isset($_GET['Action'])) ? strtolower($_GET['Action']) : null;
		$user = GetUser();

		$secondary_actions = array('step2', 'sendpreview', 'view', 'processpaging', 'activate', 'deactivate', 'pause', 'resume', 'change', 'checkspam', 'viewcompatibility');
		if (in_array($action, $secondary_actions)) {
			$access = $user->HasAccess('Autoresponders');
		} else {
			$access = $user->HasAccess('Autoresponders', $action);
		}

		$popup = (in_array($action, $this->PopupWindows)) ? true : false;
		if (!in_array($action, $this->SuppressHeaderFooter)) {
			$this->PrintHeader($popup);
		}

		if (!$access) {
			if (!$popup) {
				$this->DenyAccess();
				return;
			}
		}

		/**
		 * Check user permission to see whether or not they have access to the autoresponder
		 */
			$tempAPI = null;
			$tempCheckActions = array('activate', 'deactivate', 'copy', 'change', 'pause', 'resume', 'delete', 'step2', 'sendpreview', 'view', 'edit');
			$tempID = null;

			if (isset($_GET['id'])) {
				$tempID = $_GET['id'];
			} elseif(isset($_POST['autoresponders'])) {
				$tempID = $_POST['autoresponders'];
			}

			if (!is_null($tempID)) {
				$_GET['id'] = $tempID;
				$_POST['autoresponders'] = $tempID;

				if (!$user->Admin() && in_array($action, $tempCheckActions)) {
					if (!is_array($tempID)) {
						$tempID = array($tempID);
					}

					$tempAPI = $this->GetApi();

					foreach ($tempID as $tempEachID) {
						$tempEachID = intval($tempEachID);
						if ($tempEachID == 0) {
							continue;
						}

						if (!$tempAPI->Load($tempEachID)) {
							continue;
						}

						if ($tempAPI->ownerid != $user->userid) {
							$this->DenyAccess();
							return;
						}
					}
				}
			}

			unset($tempID);
			unset($tempCheckActions);
			unset($tempAPI);
		/**
		 * -----
		 */

		if ($action == 'processpaging') {
			$this->SetPerPage($_GET['PerPageDisplay']);
			$action = 'step2';
		}


		switch ($action) {
			case 'pause':
			case 'resume': 
				$autoresponderAPI = $this->GetApi();
				$autoresponderID = IEM::requestGetGET('id', 0, 'intval');
				$listID = IEM::requestGetGET('list', 0, 'intval');

				if ($action == 'pause') {
					$autoresponderAPI->PauseAutoresponder($autoresponderID);
				} else {
					$autoresponderAPI->ResumeAutoresponder($autoresponderID);
				}

				$this->ManageAutoresponders($listID);
			break;

			case 'viewcompatibility':
				$auto_info = IEM::sessionGet('Autoresponders');

				$html = (isset($_POST['myDevEditControl_html'])) ? $_POST['myDevEditControl_html'] : false;
				$text = (isset($_POST['TextContent'])) ? $_POST['TextContent'] : false;
				$showBroken = isset($_REQUEST['ShowBroken']) && $_REQUEST['ShowBroken'] == 1;
				$details = array();
				$details['htmlcontent'] = $html;
				$details['textcontent'] = $text;
				$details['format'] = $auto_info['Format'];

				$this->PreviewWindow($details, $showBroken);
				exit;
			break;

			case 'checkspamdisplay':
				$force = IEM::ifsetor($_GET['Force'], false);
				$this->CheckContentForSpamDisplay($force);
			break;

			case 'checkspam':
				$text = (isset($_POST['TextContent'])) ? $_POST['TextContent'] : false;
				$html = (isset($_POST['myDevEditControl_html'])) ? $_POST['myDevEditControl_html'] : false;
				$this->CheckContentForSpam($text, $html);
			break;

			case 'activate':
			case 'deactivate':
				$access = $user->HasAccess('Autoresponders', 'Approve');
				if (!$access) {
					$this->DenyAccess();
					break;
				}

				$id = (int)$_GET['id'];
				$autoapi = $this->GetApi();
				$autoapi->Load($id);
				if ($action == 'activate') {
					$prob_found = false;
					$max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024);
					if ($max_size > 0) {
						if ($autoapi->Get('autorespondersize') > $max_size) {
							$prob_found = true;
							if ($autoapi->Get('embedimages')) {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed';
							} else {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed';
							}
							$GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0));
							$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
						}
					}
					if (!$prob_found) {
						$allow_attachments = $this->CheckForAttachments($id, 'autoresponders');
						if ($allow_attachments) {
							$autoapi->Set('active', $user->Get('userid'));
							$GLOBALS['Message'] = $this->PrintSuccess('AutoresponderActivatedSuccessfully');
						} else {
							$GLOBALS['Error'] = GetLang('AutoresponderActivateFailed_HasAttachments');
							$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
						}
					}
				} else {
					$autoapi->Set('active', 0);
					$GLOBALS['Message'] = $this->PrintSuccess('AutoresponderDeactivatedSuccessfully');
				}
				$autoapi->Save();

				if (isset($_GET['list'])) {
					$listid = (int)$_GET['list'];
				}

				$this->ManageAutoresponders($listid);
			break;

			case 'copy':
				$id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
				$api = $this->GetApi();
				list($result, $files_copied) = $api->Copy($id);
				if (!$result) {
					$GLOBALS['Error'] = GetLang('AutoresponderCopyFail');
					$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
				} else {
					$api->Set('active', 0);
					$api->Save();
					$GLOBALS['Message'] = $this->PrintSuccess('AutoresponderCopySuccess');
					$GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled');
					if (!$files_copied) {
						$GLOBALS['Error'] = GetLang('AutoresponderFilesCopyFail');
						$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
					}
				}
				if (isset($_GET['list'])) {
					$listid = (int)$_GET['list'];
				}

				$this->ManageAutoresponders($listid);
			break;

			case 'change':
				$subaction = strtolower($_POST['ChangeType']);
				$autolist = $_POST['autoresponders'];

				switch ($subaction) {
					case 'delete':
						$access = $user->HasAccess('Autoresponders', 'Delete');
						if ($access) {
							$this->DeleteAutoresponders($autolist);
						} else {
							$this->DenyAccess();
						}
					break;

					case 'approve':
					case 'disapprove':
						$access = $user->HasAccess('Autoresponders', 'Approve');
						if ($access) {
							$this->ActionAutoresponders($autolist, $subaction);
						} else {
							$this->DenyAccess();
						}
					break;
				}
			break;

			case 'delete':
				$id = (int)$_GET['id'];
				$autolist = array($id);
				$access = $user->HasAccess('Autoresponders', 'Delete');
				if ($access) {
					$this->DeleteAutoresponders($autolist);
				} else {
					$this->DenyAccess();
				}
			break;

			case 'step2':
				$listid = 0;
				if (isset($_GET['list'])) {
					$listid = (int)$_GET['list'];
				}

				$this->ManageAutoresponders($listid);
			break;

			case 'sendpreviewdisplay':
				$this->SendPreviewDisplay();
			break;

			case 'sendpreview':
				$this->SendPreview();
			break;

			case 'view':
				$id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
				$type = strtolower(get_class($this));
				$autoresponderapi = $this->GetApi();
				if (!$autoresponderapi->Load($id)) {
					break;
				}

				// Log this to "User Activity Log"
				$logURL = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=' . __CLASS__ . '&Action=Edit&id=' . $_GET['id'];
				IEM::logUserActivity($logURL, 'images/autoresponders_view.gif', $autoresponderapi->name);

				$details = array();
				$details['htmlcontent'] = $autoresponderapi->GetBody('HTML');
				$details['textcontent'] = $autoresponderapi->GetBody('Text');
				$details['format'] = $autoresponderapi->format;
				$this->PreviewWindow($details);
			break;

			case 'edit':
				$subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : false;

				switch ($subaction) {
					case 'save':
					case 'complete':
						$user = IEM::getCurrentUser();
						$session_autoresponder = IEM::sessionGet('Autoresponders');

						$listid = $session_autoresponder['list'];

						if (!$session_autoresponder || !isset($session_autoresponder['autoresponderid'])) {
							$this->ManageAutoresponders($listid);
							break;
						}

						$text_unsubscribelink_found = true;
						$html_unsubscribelink_found = true;

						$id = $session_autoresponder['autoresponderid'];

						$autoapi = $this->GetApi();
						$autoapi->Load($id);

						$autoapi->Set('listid', $listid);

						if (isset($_POST['TextContent'])) {
							$textcontent = $_POST['TextContent'];
							$autoapi->SetBody('Text', $textcontent);
							$text_unsubscribelink_found = $this->CheckForUnsubscribeLink($textcontent, 'text');
							$session_autoresponder['contents']['text'] = $textcontent;
						}

						if (isset($_POST['myDevEditControl_html'])) {
							$htmlcontent = $_POST['myDevEditControl_html'];

							/**
							 * This is an effort not to overwrite the eixsting HTML contents
							 * if there isn't any contents in it (DevEdit will have '<html><body></body></html>' as a minimum
							 * that will be passed to here)
							 */
							if (trim($htmlcontent) == '') {
								$GLOBALS['Error'] = GetLang('UnableToUpdateAutoresponder');
								$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
								$this->EditAutoresponderStep4($id);
								break;
							}

							$autoapi->SetBody('HTML', $htmlcontent);
							$html_unsubscribelink_found = $this->CheckForUnsubscribeLink($htmlcontent, 'html');
							$session_autoresponder['contents']['html'] = $htmlcontent;
						}

						if (isset($_POST['subject'])) {
							$autoapi->Set('subject', $_POST['subject']);
						}

						foreach (array('name', 'format', 'searchcriteria', 'sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'tracklinks', 'trackopens', 'multipart', 'embedimages', 'hoursaftersubscription', 'charset', 'includeexisting', 'to_firstname', 'to_lastname') as $p => $area) {
							$autoapi->Set($area, $session_autoresponder[$area]);
						}

						$autoapi->Set('active', 0);

						$dest = strtolower(get_class($this));

						$movefiles_result = $this->MoveFiles($dest, $id);

						if ($movefiles_result) {
							if (isset($textcontent)) {
								$textcontent = $this->ConvertContent($textcontent, $dest, $id);
								$autoapi->SetBody('Text', $textcontent);
							}
							if (isset($htmlcontent)) {
								$htmlcontent = $this->ConvertContent($htmlcontent, $dest, $id);
								$autoapi->SetBody('HTML', $htmlcontent);
							}
						}

						// Delete any attachments we're meant to first
						if (SENDSTUDIO_ALLOW_ATTACHMENTS) {
							list($del_attachments_status, $del_attachments_status_msg) = $this->CleanupAttachments($dest, $id);

							if ($del_attachments_status) {
								if ($del_attachments_status_msg) {
									$GLOBALS['Success'] = $del_attachments_status_msg;
									$GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false);
								}
							} else {
								$GLOBALS['Error'] = $del_attachments_status_msg;
								$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
							}

							// Only save the new attachments after deleting the old ones
							list($attachments_status, $attachments_status_msg) = $this->SaveAttachments($dest, $id);

							if ($attachments_status) {
								if ($attachments_status_msg != '') {
									$GLOBALS['Success'] = $attachments_status_msg;
									$GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false);
								}
							} else {
								$GLOBALS['AttachmentError'] = $attachments_status_msg;
								$GLOBALS['Error'] = $attachments_status_msg;
								$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
							}
						}

						list($autoresponder_size, $autoresponder_img_warnings) = $this->GetSize($session_autoresponder);
						$GLOBALS['Message'] .= $this->PrintSuccess('AutoresponderUpdated', sprintf(GetLang('Autoresponder_Size_Approximate'), $this->EasySize($autoresponder_size)));
						$max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024);

						if (SENDSTUDIO_EMAILSIZE_WARNING > 0) {
							$warning_size = SENDSTUDIO_EMAILSIZE_WARNING * 1024;
							if ($autoresponder_size > $warning_size && ($max_size > 0 && $autoresponder_size < $max_size)) {
								if ($session_autoresponder['embedimages']) {
									$warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_Embed';
								} else {
									$warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_No_Embed';
								}
								$GLOBALS['Message'] .= $this->PrintWarning($warning_langvar, $this->EasySize($warning_size));
							}
						}

						if ($max_size > 0 && $autoresponder_size >= $max_size) {
							if ($session_autoresponder['embedimages']) {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed';
							} else {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed';
							}
							$GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0));

							$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
						}

						$autoapi->Set('autorespondersize', $autoresponder_size);

						$result = $autoapi->Save();

						if (!$result) {
							$GLOBALS['Error'] = GetLang('UnableToUpdateAutoresponder');
							$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
							$this->ManageAutoresponders($listid);
							break;
						}

						if ($autoresponder_img_warnings) {
							if ($session_autoresponder['embedimages']) {
								$warning_var = 'UnableToLoadImage_Autoresponder_List_Embed';
							} else {
								$warning_var = 'UnableToLoadImage_Autoresponder_List';
							}
							$GLOBALS['Message'] .= $this->PrintWarning($warning_var, $autoresponder_img_warnings);
						}

						if (!$html_unsubscribelink_found) {
							$GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInHTMLContent');
						}

						if (!$text_unsubscribelink_found) {
							$GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInTextContent');
						}
						
                        if(is_dir(TEMP_DIRECTORY . "/autoresponders/".$user->userid."_tmp")){remove_directory(TEMP_DIRECTORY . "/autoresponders/".$user->userid."_tmp");}


						if ($subaction == 'save') {
							$GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled_Save');

							$GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']);

							$this->EditAutoresponderStep4($id);
							break;
						}

						$GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled');

						$GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']);

						$this->ManageAutoresponders($listid);

					break;

					case 'step4':
						$sessionauto = IEM::sessionGet('Autoresponders');

						$sessionauto['sendfromname'] = $_POST['sendfromname'];
						$sessionauto['sendfromemail'] = $_POST['sendfromemail'];
						$sessionauto['replytoemail'] = $_POST['replytoemail'];
						$sessionauto['bounceemail'] = $_POST['bounceemail'];

						$sessionauto['charset'] = $_POST['charset'];

						$sessionauto['format'] = $_POST['format'];
						$sessionauto['hoursaftersubscription'] = (int)$_POST['hoursaftersubscription'];
						$sessionauto['trackopens'] = (isset($_POST['trackopens'])) ? true : false;
						$sessionauto['tracklinks'] = (isset($_POST['tracklinks'])) ? true : false;
						$sessionauto['multipart'] = (isset($_POST['multipart'])) ? true : false;
						$sessionauto['embedimages'] = (isset($_POST['embedimages'])) ? true : false;
						$sessionauto['includeexisting'] = (isset($_POST['includeexisting'])) ? true : false;

						$sessionauto['to_lastname'] = 0;
						if (isset($_POST['to_lastname'])) {
							$sessionauto['to_lastname'] = (int)$_POST['to_lastname'];
						}
						$sessionauto['to_firstname'] = 0;
						if (isset($_POST['to_firstname'])) {
							$sessionauto['to_firstname'] = (int)$_POST['to_firstname'];
						}

						IEM::sessionSet('Autoresponders', $sessionauto);

						$this->EditAutoresponderStep4($sessionauto['autoresponderid']);
					break;

					case 'step3':
						$sessionauto = IEM::sessionGet('Autoresponders');
						$sessionauto['name'] = $_POST['name'];
						$sessionauto['searchcriteria'] = array(
							'emailaddress' => '',
							'format' => '-1',
							'confirmed' => '1',
							'search_options' => array(),
							'customfields' => array()
						);

						if ($_POST['ShowFilteringOptions'] == 1) {
							$sessionauto['searchcriteria']['emailaddress'] = $_POST['emailaddress'];
							$sessionauto['searchcriteria']['format'] = $_POST['format'];
							$sessionauto['searchcriteria']['confirmed'] = $_POST['confirmed'];

							$search_options = (isset($_POST['Search_Options'])) ? $_POST['Search_Options'] : array();
							$sessionauto['searchcriteria']['search_options'] = $search_options;

							$customfields = (isset($_POST['CustomFields'])) ? $_POST['CustomFields'] : array();
							$sessionauto['searchcriteria']['customfields'] = $customfields;

							foreach ($sessionauto['searchcriteria']['customfields'] as $fieldid => $fieldvalue) {
								if (!$fieldvalue) {
									unset($sessionauto['searchcriteria']['customfields'][$fieldid]);
									continue;
								}
							}

							if (isset($_POST['clickedlink']) && isset($_POST['linkid'])) {
								$sessionauto['searchcriteria']['linktype'] = 'clicked';
								if (isset($_POST['linktype']) && $_POST['linktype'] == 'not_clicked') {
									$sessionauto['searchcriteria']['linktype'] = 'not_clicked';
								}

								$sessionauto['searchcriteria']['link'] = $_POST['linkid'];
							}

							if (isset($_POST['openednewsletter']) && isset($_POST['newsletterid'])) {
								$sessionauto['searchcriteria']['opentype'] = 'opened';
								if (isset($_POST['opentype']) && $_POST['opentype'] == 'not_opened') {
									$sessionauto['searchcriteria']['opentype'] = 'not_opened';
								}

								$sessionauto['searchcriteria']['newsletter'] = $_POST['newsletterid'];
							}
						}

						IEM::sessionSet('Autoresponders', $sessionauto);

						$this->EditAutoresponderStep3($sessionauto['autoresponderid']);
					break;

					default:
						$id = (int)$_GET['id'];

						IEM::sessionRemove('Autoresponders');
						$autosession = array('list' => (int)$_GET['list'], 'autoresponderid' => $id);
						IEM::sessionSet('Autoresponders', $autosession);

						$this->EditAutoresponderStep1($id);
				}
			break;

			case 'create':
				$subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : false;

				switch ($subaction) {

					case 'save':
					case 'complete':
						$autoresponder = $this->GetApi();

						$user = IEM::getCurrentUser();
						$session_autoresponder = IEM::sessionGet('Autoresponders');

						if (!$session_autoresponder || !isset($session_autoresponder['name'])) {
							$this->ManageAutoresponders($listid);
							break;
						}

						$text_unsubscribelink_found = true;
						$html_unsubscribelink_found = true;

						$listid = $session_autoresponder['list'];

						$autoresponder->Set('listid', $listid);

						if (isset($_POST['TextContent'])) {
							$textcontent = $_POST['TextContent'];
							$autoresponder->SetBody('Text', $textcontent);
							$text_unsubscribelink_found = $this->CheckForUnsubscribeLink($textcontent, 'text');
							$session_autoresponder['contents']['text'] = $textcontent;
						}

						if (isset($_POST['myDevEditControl_html'])) {
							$htmlcontent = $_POST['myDevEditControl_html'];
							$autoresponder->SetBody('HTML', $htmlcontent);
							$html_unsubscribelink_found = $this->CheckForUnsubscribeLink($htmlcontent, 'html');
							$session_autoresponder['contents']['html'] = $htmlcontent;
						}

						if (isset($_POST['subject'])) {
							$autoresponder->Set('subject', $_POST['subject']);
						}

						foreach (array('name', 'format', 'searchcriteria', 'sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'tracklinks', 'trackopens', 'multipart', 'embedimages', 'hoursaftersubscription', 'charset', 'includeexisting', 'to_firstname', 'to_lastname') as $p => $area) {
							$autoresponder->Set($area, $session_autoresponder[$area]);
						}

						$autoresponder->Set('active', 0);

						$autoresponder->ownerid = $user->userid;

						$result = $autoresponder->Create();

						if (!$result) {
							$GLOBALS['Error'] = GetLang('UnableToCreateAutoresponder');
							$GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
							$this->ManageAutoresponders($listid);
							break;
						}

						/**
						* explicitly set the 'includeexisting' flag to false so we don't import the existing subscribers twice.
						* Create() & Save() both call ImportQueue if this flag is set, so ensure we don't do it twice.
						*/
						$autoresponder->Set('includeexisting', false);

						$session_autoresponder['autoresponderid'] = $result;
						IEM::sessionSet('Autoresponders', $session_autoresponder);

						if (SENDSTUDIO_ALLOW_ATTACHMENTS) {
							$dest = strtolower(get_class($this));
							$movefiles_result = $this->MoveFiles($dest, $result);
							if ($movefiles_result) {
								if (isset($textcontent)) {
									$textcontent = $this->ConvertContent($textcontent, $dest, $result);
									$autoresponder->SetBody('Text', $textcontent);
								}
								if (isset($htmlcontent)) {
									$htmlcontent = $this->ConvertContent($htmlcontent, $dest, $result);
									$autoresponder->SetBody('HTML', $htmlcontent);
								}
							}

							list($attachments_status, $attachments_status_msg) = $this->SaveAttachments($dest, $result);

							if ($attachments_status) {
								if ($attachments_status_msg != '') {
									$GLOBALS['Success'] = $attachments_status_msg;
									$GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false);
								}
							} else {
								$GLOBALS['Error'] = $attachments_status_msg;
								$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
							}
						}

						list($autoresponder_size, $autoresponder_img_warnings) = $this->GetSize($session_autoresponder);
						$GLOBALS['Message'] .= $this->PrintSuccess('AutoresponderUpdated', sprintf(GetLang('Autoresponder_Size_Approximate'), $this->EasySize($autoresponder_size)));
						$max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024);

						if (SENDSTUDIO_EMAILSIZE_WARNING > 0) {
							$warning_size = SENDSTUDIO_EMAILSIZE_WARNING * 1024;
							if ($autoresponder_size > $warning_size && ($max_size > 0 && $autoresponder_size < $max_size)) {
								if ($session_autoresponder['embedimages']) {
									$warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_Embed';
								} else {
									$warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_No_Embed';
								}
								$GLOBALS['Message'] .= $this->PrintWarning($warning_langvar, $this->EasySize($warning_size));
							}
						}

						if ($max_size > 0 && $autoresponder_size >= $max_size) {
							if ($session_autoresponder['embedimages']) {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed';
							} else {
								$error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed';
							}
							$GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0));

							$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
						}

						$autoresponder->Set('autorespondersize', $autoresponder_size);

						$autoresponder->Save();

						if ($autoresponder_img_warnings) {
							if ($session_autoresponder['embedimages']) {
								$warning_var = 'UnableToLoadImage_Autoresponder_List_Embed';
							} else {
								$warning_var = 'UnableToLoadImage_Autoresponder_List';
							}
							$GLOBALS['Message'] .= $this->PrintWarning($warning_var, $autoresponder_img_warnings);
						}

						if (!$html_unsubscribelink_found) {
							$GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInHTMLContent');
						}

						if (!$text_unsubscribelink_found) {
							$GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInTextContent');
						}

						if ($subaction == 'save') {
							$GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled_Save');
							$GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']);
							$this->EditAutoresponderStep4($result);
							break;
						}

						$GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled');

						$GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']);

						$this->ManageAutoresponders($listid);
					break;

					case 'step4':
						$sessionauto = IEM::sessionGet('Autoresponders');

						$sessionauto['sendfromname'] = $_POST['sendfromname'];
						$sessionauto['sendfromemail'] = $_POST['sendfromemail'];
						$sessionauto['replytoemail'] = $_POST['replytoemail'];
						$sessionauto['bounceemail'] = $_POST['bounceemail'];

						$sessionauto['charset'] = $_POST['charset'];

						$sessionauto['format'] = $_POST['format'];
						$sessionauto['hoursaftersubscription'] = (int)$_POST['hoursaftersubscription'];
						$sessionauto['trackopens'] = (isset($_POST['trackopens'])) ? true : false;
						$sessionauto['tracklinks'] = (isset($_POST['tracklinks'])) ? true : false;
						$sessionauto['multipart'] = (isset($_POST['multipart'])) ? true : false;
						$sessionauto['embedimages'] = (isset($_POST['embedimages'])) ? true : false;

						$sessionauto['includeexisting'] = (isset($_POST['includeexisting'])) ? true : false;

						$sessionauto['to_lastname'] = 0;
						if (isset($_POST['to_lastname'])) {
							$sessionauto['to_lastname'] = (int)$_POST['to_lastname'];
						}

						$sessionauto['to_firstname'] = 0;
						if (isset($_POST['to_firstname'])) {
							$sessionauto['to_firstname'] = (int)$_POST['to_firstname'];
						}

						if (isset($_POST['TemplateID'])) {
							$sessionauto['TemplateID'] = $_POST['TemplateID'];
						}

						IEM::sessionSet('Autoresponders', $sessionauto);

						$this->EditAutoresponderStep4();

					break;

					case 'step3':
						$sessionauto = IEM::sessionGet('Autoresponders');
						$sessionauto['name'] = $_POST['name'];
						$sessionauto['searchcriteria'] = array(
							'emailaddress' => '',
							'format' => '-1',
							'confirmed' => '1',
							'search_options' => array(),
							'customfields' => array()
						);

						if ($_POST['ShowFilteringOptions'] == 1) {
							$sessionauto['searchcriteria']['emailaddress'] = $_POST['emailaddress'];
							$sessionauto['searchcriteria']['format'] = $_POST['format'];
							$sessionauto['searchcriteria']['confirmed'] = $_POST['confirmed'];

							$search_options = (isset($_POST['Search_Options'])) ? $_POST['Search_Options'] : array();
							$sessionauto['searchcriteria']['search_options'] = $search_options;

							$customfields = (isset($_POST['CustomFields'])) ? $_POST['CustomFields'] : array();
							$sessionauto['searchcriteria']['customfields'] = $customfields;

							foreach ($sessionauto['searchcriteria']['customfields'] as $fieldid => $fieldvalue) {
								if (!$fieldvalue) {
									unset($sessionauto['searchcriteria']['customfields'][$fieldid]);
									continue;
								}
							}

							if (isset($_POST['clickedlink']) && isset($_POST['linkid'])) {
								$sessionauto['searchcriteria']['linktype'] = 'clicked';
								if (isset($_POST['linktype']) && $_POST['linktype'] == 'not_clicked') {
									$sessionauto['searchcriteria']['linktype'] = 'not_clicked';
								}

								$sessionauto['searchcriteria']['link'] = $_POST['linkid'];
							}

							if (isset($_POST['openednewsletter']) && isset($_POST['newsletterid'])) {
								$sessionauto['searchcriteria']['opentype'] = 'opened';
								if (isset($_POST['opentype']) && $_POST['opentype'] == 'not_opened') {
									$sessionauto['searchcriteria']['opentype'] = 'not_opened';
								}

								$sessionauto['searchcriteria']['newsletter'] = $_POST['newsletterid'];
							}
						}

						IEM::sessionSet('Autoresponders', $sessionauto);

						$this->EditAutoresponderStep3();
					break;

					case 'step2':
						$listid = 0;
						if (isset($_POST['list'])) {
							$listid = (int)$_POST['list'];
						}

						if (isset($_GET['list'])) {
							$listid = (int)$_GET['list'];
						}

						$auto = array('list' => $listid);

						IEM::sessionSet('Autoresponders', $auto);

						$this->EditAutoresponderStep1();
					break;

					default:
						IEM::sessionRemove('Autoresponders');
						$this->ChooseCreateList();
				}
			break;

			default:
				$this->SetCurrentPage(1);
				$this->ChooseList('Autoresponders', 'step2');
			break;
		}

		if (!in_array($action, $this->SuppressHeaderFooter)) {
			$this->PrintFooter($popup);
		}
	}
Пример #25
0
function remove_directory($path)
{
    if ($dp = opendir($path)) {
        while (($entry = readdir($dp)) !== false) {
            if ($entry == ".") {
                continue;
            }
            if ($entry == "..") {
                continue;
            }
            if (is_link("{$path}/{$entry}")) {
                unlink("{$path}/{$entry}");
            } else {
                if (is_dir("{$path}/{$entry}")) {
                    remove_directory("{$path}/{$entry}");
                } else {
                    unlink("{$path}/{$entry}");
                }
            }
        }
        closedir($dp);
        rmdir($path);
    }
}
Пример #26
0
    /**
     * ManageNewsletters
     * Prints out the newsletters for management. Depending on your access levels you can edit, delete, send, schedule and so on.
     *
     * @see GetPerPage
     * @see GetSortDetails
     * @see GetApi
     * @see User_API::Admin
     * @see Newsletter_API::GetNewsletters
     * @see SetupPaging
     * @see PrintDate
     * @see User_API::HasWriteAccess
     * @see Jobs_API::FindJob
     *
     * @return Void Doesn't return anything, just prints out the results and that's it.
     *
     * @uses EventData_IEM_NEWSLETTERS_MANAGENEWSLETTERS
     */
    function ManageNewsletters() {        
        $user = GetUser();
        
        $remove_temp_dir = IEM::sessionGet('Newsletters_creation['.$user->Get('userid').']');
        IEM::sessionSet('Newsletters_creation['.$user->Get('userid').']',null);
        IEM::sessionRemove('Newsletter_creation['.$user->Get('userid').']');
        if(!empty($remove_temp_dir)){
            $d_path = TEMP_DIRECTORY . DIRECTORY_SEPARATOR . "newsletters" . DIRECTORY_SEPARATOR . $user->Get('userid')."_tmp";
            if(is_dir($d_path)){remove_directory($d_path);}
            $GLOBALS['Message'] = $remove_temp_dir;    
        }

        $edit_msg = IEM::sessionGet('Newsletters_editing['.$user->Get('userid').']');
        IEM::sessionSet('Newsletters_editing['.$user->Get('userid').']',null);
        IEM::sessionRemove('Newsletters_editing['.$user->Get('userid').']');
        if(!empty($edit_msg)){
            $GLOBALS['Message'] = $edit_msg;    
        }        

        $delete_msg = IEM::sessionGet('Newsletters_deletion['.$user->Get('userid').']');
        IEM::sessionSet('Newsletters_deletion['.$user->Get('userid').']',null);
        IEM::sessionRemove('Newsletters_deletion['.$user->Get('userid').']');
        if(!empty($delete_msg)){
            $GLOBALS['Message'] = $delete_msg;    
        }         
        $perpage = $this->GetPerPage();

        $DisplayPage = $this->GetCurrentPage();
        $start = 0;
        if ($perpage != 'all') {
            $start = ($DisplayPage - 1) * $perpage;
        }

        $sortinfo = $this->GetSortDetails();

        $newsletterapi = $this->GetApi();

        $newsletterowner = ($user->Admin() || $user->AdminType() == 'n') ? 0 : $user->userid;
        $NumberOfNewsletters = $newsletterapi->GetNewsletters($newsletterowner, $sortinfo, true);
        $mynewsletters = $newsletterapi->GetNewsletters($newsletterowner, $sortinfo, false, $start, $perpage, true);

        if ($user->HasAccess('Newsletters', 'Create')) {
            $GLOBALS['Newsletters_AddButton'] = $this->ParseTemplate('Newsletter_Create_Button', true, false);
            $GLOBALS['Newsletters_Heading'] = GetLang('Help_NewslettersManage_HasAccess');
        }

        if (!isset($GLOBALS['Message'])) {
            $GLOBALS['Message'] = '';
        }

        /**
         * Trigger event
         */
        $tempEventData = new EventData_IEM_NEWSLETTERS_MANAGENEWSLETTERS();
        $tempEventData->displaymessage = &$GLOBALS['Message'];
        $tempEventData->trigger();

        unset($tempEventData);
        /**
         * -----
         */
        if ($NumberOfNewsletters == 0) {
            if ($user->HasAccess('Newsletters', 'Create')) {
                $GLOBALS['Message'] .= $this->PrintSuccess('NoNewsletters', GetLang('NoNewsletters_HasAccess'));
            } else {
                $GLOBALS['Message'] .= $this->PrintSuccess('NoNewsletters', '');
            }
            $this->ParseTemplate('Newsletters_Manage_Empty');
            return;
        }

        $this->SetupPaging($NumberOfNewsletters, $DisplayPage, $perpage);
        $GLOBALS['FormAction'] = 'Action=ProcessPaging';
        $paging = $this->ParseTemplate('Paging', true, false);

        if ($user->HasAccess('Newsletters', 'Delete')) {
            $GLOBALS['Option_DeleteNewsletter'] = '<option value="Delete">' . GetLang('Delete') . '</option>';
        }

        if ($user->HasAccess('Newsletters', 'Approve')) {
            $GLOBALS['Option_ActivateNewsletter'] = '<option value="Approve">' . GetLang('ApproveNewsletters') . '</option>';
            $GLOBALS['Option_ActivateNewsletter'] .= '<option value="Disapprove">' . GetLang('DisapproveNewsletters') . '</option>';
            $GLOBALS['Option_ArchiveNewsletter'] = '<option value="Archive">' . GetLang('ArchiveNewsletters') . '</option>';
            $GLOBALS['Option_ArchiveNewsletter'] .= '<option value="Unarchive">' . GetLang('UnarchiveNewsletters') . '</option>';
        }

        $newsletter_manage = $this->ParseTemplate('Newsletters_Manage', true, false);

        $newsletterdisplay = '';

        $jobapi = $this->GetApi('Jobs');

        foreach ($mynewsletters as $pos => $newsletterdetails) {
            $newsletterid = $newsletterdetails['newsletterid'];
            $GLOBALS['Name'] = htmlspecialchars($newsletterdetails['name'], ENT_QUOTES, SENDSTUDIO_CHARSET);
            $GLOBALS['Short_Name'] = htmlspecialchars($this->TruncateName($newsletterdetails['name'], 34), ENT_QUOTES, SENDSTUDIO_CHARSET);

            $GLOBALS['Created'] = $this->PrintDate($newsletterdetails['createdate']);
            $GLOBALS['Format'] = GetLang('Format_' . $newsletterapi->GetFormat($newsletterdetails['format']));
            $GLOBALS['Owner'] = $newsletterdetails['owner'];

            $GLOBALS['Subject'] = htmlspecialchars($newsletterdetails['subject'], ENT_QUOTES, SENDSTUDIO_CHARSET);
            $GLOBALS['Short_Subject'] = htmlspecialchars($this->TruncateName($newsletterdetails['subject'], 37), ENT_QUOTES, SENDSTUDIO_CHARSET);

            $GLOBALS['id'] = $newsletterid;

            $GLOBALS['NewsletterIcon'] = '<img src="images/m_newsletters.gif">';

            $GLOBALS['NewsletterAction'] = '<a href="index.php?Page=Newsletters&Action=View&id=' . $newsletterid . '" target="_blank">' . GetLang('View') . '</a>';

            $send_inprogress = false;
            $send_fully_completed = true;

            $job = false;
            if ($newsletterdetails['jobid'] > 0) {
                $job = $jobapi->LoadJob($newsletterdetails['jobid']);
            }

            $GLOBALS['LastSentTip'] = $GLOBALS['LastSentTip_Extra'] = $GLOBALS['Job'] = '';

            if ($newsletterdetails['starttime'] > 0) {
                $GLOBALS['LastSent'] = $this->PrintDate($newsletterdetails['starttime']);

                $GLOBALS['TipName'] = $this->GetRandomId();

                if ($newsletterdetails['finishtime'] > 0) {
                    $GLOBALS['LastSentTip'] = sprintf(GetLang('AlreadySentTo'), $this->FormatNumber($newsletterdetails['total_recipients']), $this->FormatNumber($newsletterdetails['sendsize']));
                    if ($newsletterdetails['total_recipients'] < $newsletterdetails['sendsize'] && $job) {
                        $send_fully_completed = false;
                        $GLOBALS['ResendTipName'] = $this->GetRandomId();
                        $GLOBALS['Job'] = $job['jobid'];
                        if ($job['resendcount'] < SENDSTUDIO_RESEND_MAXIMUM) {
                            $GLOBALS['NewsletterIcon'] = $this->ParseTemplate('Newsletters_Send_Resend_Tip', true, false);
                            $GLOBALS['LastSentTip_Extra'] = GetLang('AlreadySentTo_Partial');
                        }
                    }
                } else {
                    $GLOBALS['LastSentTip'] = sprintf(GetLang('AlreadySentTo_SoFar'), $this->FormatNumber($newsletterdetails['total_recipients']), $this->FormatNumber($newsletterdetails['sendsize']));
                }

                $already_sent_tip = $this->ParseTemplate('Newsletters_Send_Tip', true, false);

                $GLOBALS['LastSent'] = $already_sent_tip;
            } else {
                $GLOBALS['LastSent'] = GetLang('NotSent');
            }

            if ($user->HasAccess('Newsletters', 'Send')) {
                if ($newsletterdetails['active']) {
                    if (!$job || empty($job)) {
                        $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Send&id=' . $newsletterid . '">' . GetLang('Send') . '</a>';
                    } else {
                        $jobstate = $jobapi->GetJobStatus($job['jobstatus']);
                        switch ($job['jobstatus']) {
                            case 'i':
                                $send_inprogress = true;
                                if (SENDSTUDIO_CRON_ENABLED && SENDSTUDIO_CRON_SEND > 0) {
                                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Schedule">' . $jobstate . '</a>';
                                } else {
                                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Send&Action=PauseSend&Job=' . $job['jobid'] . '">' . $jobstate . '</a>';
                                }
                                break;
                            case 'p':
                                if (SENDSTUDIO_CRON_ENABLED && SENDSTUDIO_CRON_SEND > 0) {
                                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Schedule">' . $jobstate . '</a>';
                                } else {
                                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Send&Action=ResumeSend&Job=' . $job['jobid'] . '">' . $jobstate . '</a>';
                                }
                                break;
                            case 'w':
                                // this is only applicable for scheduled newsletters (waiting to send).
                                $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Schedule">' . GetLang('Waiting') . '</a>';
                                break;
                            default:
                                if ($send_fully_completed) {
                                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Send&id=' . $newsletterid . '">' . GetLang('Send') . '</a>';
                                } else {
                                    if ($job['resendcount'] < SENDSTUDIO_RESEND_MAXIMUM) {
                                        $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Send&Action=Resend&Job=' . $job['jobid'] . '">' . GetLang('Resend') . '</a>';
                                    } else {
                                        $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Resend', 'Newsletter_Send_Disabled_Resend_Maximum');
                                    }
                                }
                        }
                    }
                } else {
                    $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Send', 'Newsletter_Send_Disabled_Inactive');
                }
            } else {
                $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Send');
            }

            if ($user->HasAccess('Newsletters', 'Edit')) {
                if (!$send_inprogress) {
                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Newsletters&Action=Edit&id=' . $newsletterid . '">' . GetLang('Edit') . '</a>';
                } else {
                    $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Edit', 'Newsletter_Edit_Disabled_SendInProgress');
                }
            } else {
                $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Edit');
            }

            if ($user->HasAccess('Newsletters', 'Create')) {
                $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="index.php?Page=Newsletters&Action=Copy&id=' . $newsletterid . '">' . GetLang('Copy') . '</a>';
            } else {
                $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Copy');
            }

            if ($user->HasAccess('Newsletters', 'Delete')) {
                if (!$send_inprogress) {
                    $GLOBALS['NewsletterAction'] .= '&nbsp;&nbsp;<a href="javascript: ConfirmDelete(' . $newsletterid . ');">' . GetLang('Delete') . '</a>';
                } else {
                    $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Delete', 'Newsletter_Delete_Disabled_SendInProgress');
                }
            } else {
                $GLOBALS['NewsletterAction'] .= $this->DisabledItem('Delete');
            }

            if ($newsletterdetails['active'] > 0) {
                $statusaction = 'deactivate';
                $activeicon = 'tick';
                if ($user->HasAccess('Newsletters', 'Approve')) {
                    $activetitle = GetLang('Newsletter_Title_Disable');
                } else {
                    $activetitle = GetLang('NoAccess');
                }
            } else {
                $statusaction = 'activate';
                $activeicon = 'cross';
                if ($user->HasAccess('Newsletters', 'Approve')) {
                    $activetitle = GetLang('Newsletter_Title_Enable');
                } else {
                    $activetitle = GetLang('NoAccess');
                }
            }

            if ($user->HasAccess('Newsletters', 'Approve')) {
                if (!$send_inprogress) {
                    $GLOBALS['ActiveAction'] = '<a href="index.php?Page=Newsletters&Action=' . $statusaction . '&id=' . $newsletterid . '" title="' . $activetitle . '"><img src="images/' . $activeicon . '.gif" border="0"></a>';
                } else {
                    $activetitle = GetLang('Newsletter_ChangeActive_Disabled_SendInProgress');
                    $GLOBALS['ActiveAction'] = '<span title="' . $activetitle . '"><img src="images/' . $activeicon . '.gif" border="0"></span>';
                }
            } else {
                $GLOBALS['ActiveAction'] = '<span title="' . $activetitle . '"><img src="images/' . $activeicon . '.gif" border="0"></span>';
            }

            if ($newsletterdetails['archive'] > 0) {
                $statusaction = 'deactivatearchive';
                $activeicon = 'tick';
                $activetitle = GetLang('Newsletter_Title_Archive_Disable');
            } else {
                $statusaction = 'activatearchive';
                $activeicon = 'cross';
                $activetitle = GetLang('Newsletter_Title_Archive_Enable');
            }

            if ($user->HasAccess('Newsletters', 'Approve')) {
                $GLOBALS['ArchiveAction'] = '<a href="index.php?Page=Newsletters&Action=' . $statusaction . '&id=' . $newsletterid . '" title="' . $activetitle . '"><img src="images/' . $activeicon . '.gif" border="0"></a>';
            } else {
                $GLOBALS['ArchiveAction'] = '<span title="' . $activetitle . '"><img src="images/' . $activeicon . '.gif" border="0"></span>';
            }

            $newsletterdisplay .= $this->ParseTemplate('Newsletters_Manage_Row', true, false);
        }
        $newsletter_manage = str_replace('%%TPL_Newsletters_Manage_Row%%', $newsletterdisplay, $newsletter_manage);
        $newsletter_manage = str_replace('%%TPL_Paging%%', $paging, $newsletter_manage);
        $newsletter_manage = str_replace('%%TPL_Paging_Bottom%%', $GLOBALS['PagingBottom'], $newsletter_manage);

        echo $newsletter_manage;
    }
Пример #27
0
	/**
	* Delete
	* Delete a newsletter from the database
	*
	* @param Int $newsletterid Newsletterid of the newsletter to delete. If not passed in, it will delete 'this' newsletter. We delete the newsletter, then reset all class vars.
	* @param Int $userid The user doing the deleting of the newsletter. This is passed through to the stats api to "hide" statistics rather than deleting them.
	*
	* @see Stats_API::HideStats
	*
	* @return Boolean True if it deleted the newsletter, false otherwise.
	*
	* @uses module_TrackerFactory
	* @uses module_Tracker
	* @uses module_Tracker::DeleteRecordsForAllTrackerByID()
	*/
	function Delete($newsletterid=0, $userid=0)
	{
		if ($newsletterid == 0) {
			$newsletterid = $this->newsletterid;
		}

		$newsletterid = intval($newsletterid);

		/**
		 * Status being 'true' means
		 * it's ok to delete the newsletter.
		 * If it's not true, then the delete method returns false.
		 */
		$trigger_details = array (
			'status' => true,
			'newsletterid' => $newsletterid
		);

		/**
		 * Trigger event
		 */
			$tempEventData = new EventData_IEM_NEWSLETTERSAPI_DELETE();
			$tempEventData->status = &$trigger_details['status'];
			$tempEventData->newsletterid = &$trigger_details['newsletterid'];
			$tempEventData->trigger();

			unset($tempEventData);
		/**
		 * -----
		 */

		if ($trigger_details['status'] !== true) {
			return false;
		}

		$this->Db->StartTransaction();

		/**
		 * Cleanup trackers
		 *
		 * When newsletter are deleted, delete associated tracker record too
		 *
		 * This was added here, because it's not calling the stats API to clear it's statistic
		 */
			$tempContinue = false;
			if (!class_exists('module_TrackerFactory', false)) {
				$tempFile = dirname(__FILE__) . '/module_trackerfactory.php';
				if (is_file($tempFile)) {
					require_once($tempFile);
					$tempContinue = true;
				}
			} else {
				$tempContinue = true;
			}

			if ($tempContinue) {
				module_Tracker::DeleteRecordForAllTrackerByNewsletterID($newsletterid);
			}
		/**
		 * -----
		 */

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "newsletters WHERE newsletterid=" . $newsletterid;
		$result = $this->Db->Query($query);
		if (!$result) {
			$this->Db->RollbackTransaction();
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		$newsletter_dir = TEMP_DIRECTORY . '/newsletters/' . $newsletterid;
		remove_directory($newsletter_dir);

		$this->newsletterid = 0;
		$this->name = '';
		$this->format = 'h';
		$this->active = 0;
		$this->archive = 0;
		$this->SetBody('text', '');
		$this->SetBody('html', '');
		$this->ownerid = 0;

		$stats = array();
		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_newsletters WHERE newsletterid=" . $newsletterid;
		$result = $this->Db->Query($query);
		if (!$result) {
			$this->Db->RollbackTransaction();
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		// clean up stats
		if (!class_exists('stats_api', false)) {
			require_once(dirname(__FILE__) . '/stats.php');
		}

		$stats_api = new Stats_API();

		$stats_api->HideStats($stats, 'newsletter', $userid);

		$this->Db->CommitTransaction();

		return true;
	}