Inheritance: extends DatabaseObject
 /**
  * Add section to subscription
  *
  * @param Newscoop\Entity\Subscription
  * @param array $values
  * @return void
  */
 public function addSections(Subscription $subscription, array $values)
 {
     $em = $this->getEntityManager();
     if ($values['language'] == 'select') {
         if (empty($values['sections_select'])) {
             throw new \InvalidArgumentException('No sections specified');
         }
         foreach ($values['sections_select'] as $num_lang) {
             list($num, $lang) = explode('_', $num_lang);
             $subscriptionSection = new SubscriptionSection();
             $subscriptionSection->setSubscription($subscription)->setSectionNumber($num)->setLanguage($em->getReference('Newscoop\\Entity\\Language', $lang))->setStartDate(new \DateTime($values['start_date']))->setDays($values['days'])->setPaidDays($values['days']);
             $em->persist($subscriptionSection);
         }
     } else {
         if (empty($values['sections_all'])) {
             throw new \InvalidArgumentException('No sections specified');
         }
         foreach ($values['sections_all'] as $num) {
             $subscriptionSection = new SubscriptionSection();
             $subscriptionSection->setSubscription($subscription)->setSectionNumber($num)->setStartDate(new \DateTime($values['start_date']))->setDays($values['days'])->setPaidDays($values['days']);
             $em->persist($subscriptionSection);
         }
     }
 }
 /**
  *
  * @param int $p_subscriptionId
  * @param int $p_publicationId
  * @param int $p_languageId
  * @param array $p_values
  * @return boolean
  */
 public static function AddSubscriberToPublication($p_subscriptionId, $p_publicationId, $p_languageId, $p_values = null)
 {
     global $g_ado_db;
     $created = true;
     $queryStr = "SELECT DISTINCT Number FROM Sections where IdPublication={$p_publicationId}";
     $sectionIds = $g_ado_db->GetCol($queryStr);
     foreach ($sectionIds as $sectionId) {
         $subscriptionSection = new SubscriptionSection($p_subscriptionId, $sectionId, $p_languageId);
         $created &= $subscriptionSection->create($p_values);
     }
     return $created;
 }
示例#3
0
require_once($GLOBALS['g_campsiteDir']. '/classes/Subscription.php');
require_once($GLOBALS['g_campsiteDir']. '/classes/SubscriptionSection.php');
require_once($GLOBALS['g_campsiteDir']. '/classes/Language.php');
require_once($GLOBALS['g_campsiteDir']. '/classes/Publication.php');
require_once($GLOBALS['g_campsiteDir']."/db_connect.php");

if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}

if (!$g_user->hasPermission('ManageSubscriptions')) {
	camp_html_display_error(getGS("You do not have the right to delete subscriptions."));
	exit;
}

$f_user_id = Input::Get('f_user_id', 'int', 0);
$f_publication_id = Input::Get('f_publication_id', 'int', 0);
$f_language_id = Input::Get('f_language_id', 'int', 0);
$f_subscription_id = Input::Get('f_subscription_id', 'int', 0);
$f_section_number = Input::Get('f_section_number', 'int', 0);

$publicationObj = new Publication($f_publication_id);
$languageObj = new Language($publicationObj->getDefaultLanguageId());
$manageUser = new User($f_user_id);

$subscriptionSection = new SubscriptionSection($f_subscription_id, $f_section_number, $f_language_id);
$subscriptionSection->delete();
camp_html_goto_page("/$ADMIN/users/subscriptions/sections/?f_user_id=$f_user_id&f_subscription_id=$f_subscription_id&f_publication_id=$f_publication_id");

?>
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (PEAR::isError($this->m_error)) {
            return false;
        }

        $user = new User($p_context->user->identifier);
        if ($user->getUserId() != CampRequest::GetVar('LoginUserId')
        || $user->getKeyId() != CampRequest::GetVar('LoginUserKey')
        || $user->getUserId() == 0
        || $user->getKeyId() == 0) {
            $this->m_error = new PEAR_Error('You must be logged in to create or edit your subscription.',
            ACTION_EDIT_SUBSCRIPTION_ERR_NO_USER);
            return false;
        }

        $subscriptions = Subscription::GetSubscriptions($p_context->publication->identifier,
        $user->getUserId());
        if (count($subscriptions) == 0) {
            $subscription = new Subscription();
            $created = $subscription->create(array(
			'IdUser' => $user->getUserId(),
			'IdPublication' => $p_context->publication->identifier,
			'Active' => 'Y',
			'Type' => $this->m_subscriptionType == 'trial' ? 'T' : 'P'));
            if (!$created) {
                $this->m_error = new PEAR_Error('Internal error (code 1)',
                ACTION_EDIT_SUBSCRIPTION_ERR_INTERNAL);
                exit(1);
            }
        } else {
            $subscription = $subscriptions[0];
        }

        $publication = new Publication($p_context->publication->identifier);
        $subscriptionDays = $this->computeSubscriptionDays($publication,
        $p_context->publication->subscription_time);

        $startDate = new Date();
        
        $columns = array(
        'StartDate'=>$startDate->getDate(),
        'Days'=>$subscriptionDays,
        'PaidDays'=>($this->m_subscriptionType == 'trial' ? $subscriptionDays : 0),
        'NoticeSent'=>'N'
        );

        if ($this->m_properties['subs_by_type'] == 'publication') {
        	$sectionsList = Section::GetUniqueSections($p_context->publication->identifier);
        	foreach ($sectionsList as $section) {
        		$this->m_sections[] = $section['id'];
        	}
        }
        foreach ($this->m_languages as $languageId) {
            foreach ($this->m_sections as $sectionNumber) {
                $subsSection = new SubscriptionSection($subscription->getSubscriptionId(),
                $sectionNumber, $languageId);
                $subsSection->create($columns);
            }
        }

        $fields = array('SubsType', 'tx_subs', 'nos', 'unitcost', 'unitcostalllang',
        'f_substype', 'cb_subs', 'subs_all_languages', 'suma', 'tpl', 'subscription_language');
        foreach (CampRequest::GetInput() as $field=>$value) {
            if (strncmp('tx_subs', $field, strlen('tx_subs')) == 0) {
                $fields[] = $field;
            }
        }
        foreach ($fields as $fieldName) {
            $p_context->default_url->reset_parameter($fieldName);
            $p_context->url->reset_parameter($fieldName);
        }

        $this->m_error = ACTION_OK;
        return true;
    }
示例#5
0
$f_subscription_id = Input::Get('f_subscription_id', 'int', 0);
$f_section_number = Input::Get('f_section_number', 'int', null);
$f_subscription_start_date = Input::Get('f_subscription_start_date');
$f_subscription_days = Input::Get('f_subscription_days', 'int', 0);
$f_subscription_paid_days = Input::Get('f_subscription_paid_days', 'int', 0);

$publicationObj = new Publication($f_publication_id);
$languageObj = new Language($publicationObj->getDefaultLanguageId());
$manageUser = new User($f_user_id);
$subscription = new Subscription($f_subscription_id);
$isPaid = false;
if ($subscription->getType() == 'P') {
	$isPaid = true;
}

$subscriptionSections = SubscriptionSection::GetSubscriptionSections($f_subscription_id, $f_section_number, $f_language_id);

if (!$isPaid) {
	$f_subscription_paid_days = $f_subscription_days;
}
foreach ($subscriptionSections as $section) {
	$section->setStartDate($f_subscription_start_date);
	$section->setDays($f_subscription_days);
	$section->setPaidDays($f_subscription_paid_days);
}

camp_html_goto_page("/$ADMIN/users/subscriptions/sections/?f_publication_id=$f_publication_id&f_user_id=$f_user_id&f_subscription_id=$f_subscription_id");
exit;

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
 public function has_section($p_sectionNumber)
 {
     $today = new Date(time());
     $subscriptionId = $this->m_dbObject->getSubscriptionId();
     $section = new SubscriptionSection($subscriptionId, $p_sectionNumber, 0);
     if ($section->exists() && $section->getExpirationDate() >= $today->getDate()) {
         return (int) true;
     }
     $currentLanguageNumber = CampTemplate::singleton()->context()->language->number;
     $section = new SubscriptionSection($subscriptionId, $p_sectionNumber, $currentLanguageNumber);
     return (int) ($section->exists() && $section->getExpirationDate() >= $today->getDate());
 }
示例#7
0
} else {
	if (is_array($f_section_id)) {
		foreach ($f_section_id as $section_id) {
			$id = explode('_', $section_id);
			$new_sections[$id[0]][] = $id[1];
		}
	}
}

$columns = array('StartDate' => $f_subscription_start_date,
				 'Days' => $f_subscription_days,
				 'PaidDays' => $f_subscription_days);
foreach ($new_sections as $section_number=>$section_languages) {
	foreach ($section_languages as $section_language) {
		//echo "<p>try $section_number:$section_language</p>\n";
		$subscriptionSection = new SubscriptionSection($f_subscription_id, $section_number, $section_language);
		if (!$subscriptionSection->exists()) {
			//echo "<p>create $section_number:$section_language</p>\n";
			$success &= $subscriptionSection->create($columns);
		}
	}
}
if ($success) {
	camp_html_goto_page("/$ADMIN/users/subscriptions/sections/"
		."?f_user_id=$f_user_id&f_subscription_id=$f_subscription_id&f_publication_id=$f_publication_id");
} else {
	$errorMsgs[] = getGS('The sections could not be added successfully. Some of them were already added !');
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
示例#8
0
$manageUser = new User($f_user_id);

$sections = Section::GetUniqueSections($f_publication_id);
$sectionsByLanguage = Section::GetUniqueSections($f_publication_id, true);

$optionsAllLang = array();
foreach ($sections as $section) {
	if (SubscriptionSection::GetNumSections($f_subscription_id, $section['id'], 0) > 0) {
		continue;
	}
	$optionsAllLang[$section['id']] = $section['id'] . ' - ' . $section['name'];
}

$optionsIndividualLang = array();
foreach ($sectionsByLanguage as $section) {
	if (SubscriptionSection::GetNumSections($f_subscription_id, $section['id'], $section['IdLanguage']) > 0) {
		continue;
	}
	$id = $section['id'] . '_' . $section['IdLanguage'];
	$display = $section['id'] . ' - ' . $section['name']
		. ' (' . $section['LangName'] . ')';
	$optionsIndividualLang[$id] = $display;
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Subscribers"), "/$ADMIN/users/?uType=Subscribers");
$crumbs[] = array(getGS("Account") . " '".$manageUser->getUserName()."'",
			"/$ADMIN/users/edit.php?User=$f_user_id&uType=Subscribers");
$crumbs[] = array(getGS("Subscriptions"), "/$ADMIN/users/subscriptions/?f_user_id=$f_user_id");
$crumbs[] = array(getGS("Subscribed sections").": ".$publicationObj->getName(), "/$ADMIN/users/subscriptions/sections/?f_user_id=$f_user_id&f_subscription_id=$f_subscription_id&f_publication_id=$f_publication_id");
示例#9
0
	$errorMsgs[] = getGS('The subscription could not be added.')
				.' '.getGS("Please check if there isn't another subscription to the same publication.");
} else {
        $logtext = getGS('Subscription added for user #$1 (Publication: $2, Active: $3, Type: $4)',
			 $f_user_id, $f_publication_id, $f_subscription_active, $subsType);
        Log::Message($logtext, null, 181);
}

if ($created && ($f_add_sections_now == 'Y')) {
	$columns = array('StartDate' => $f_subscription_start_date,
			  'Days' => $f_subscription_days,
			  'PaidDays' => $paidDays);
	foreach ($f_language_id as $language_id) {
		$created = SubscriptionSection::AddSubscriberToPublication(
			$subscription->getSubscriptionId(),
			$f_publication_id,
			$language_id,
			$columns);
		if (!$created) {
			$errorMsgs[] = getGS('The sections could not be added successfully. Some of them were already added !');
			break;
		}
	}
}
if (sizeof($errorMsgs) == 0) {
	camp_html_goto_page($location);
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Subscribers"), "/$ADMIN/users/?uType=Subscribers");
示例#10
0
$manageUser = new User($f_user_id);
$sections = SubscriptionSection::GetSubscriptionSections($f_subscription_id);

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Subscribers"), "/$ADMIN/users/?uType=Subscribers");
$crumbs[] = array(getGS("Account") . " '".$manageUser->getUserName()."'",
"/$ADMIN/users/edit.php?User=$f_user_id&uType=Subscribers");
$crumbs[] = array(getGS("Subscriptions"), "/$ADMIN/users/subscriptions/?f_user_id=$f_user_id");
$crumbs[] = array(getGS("Subscribed sections").": ".$publicationObj->getName(), "");
echo camp_html_breadcrumbs($crumbs);

$subscription_num_sections = SubscriptionSection::GetNumSections($f_subscription_id);
$publication_num_sections = Section::GetNumUniqueSections($f_publication_id);

$subscription_num_sections_nolang = SubscriptionSection::GetNumSections($f_subscription_id, null, 0);
$publication_num_sections_nolang = Section::GetNumUniqueSections($f_publication_id, false);

?>
<P>
<table cellpadding="0" cellspacing="0" class="action_buttons">
<tr>
	<td valign=top>
		<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
<?php
if ($subscription_num_sections < $publication_num_sections
	|| $subscription_num_sections_nolang < $publication_num_sections_nolang) {
?>
		<TR>
			<TD><A HREF="add.php?f_subscription_id=<?php p($f_subscription_id); ?>&f_publication_id=<?php p($f_publication_id); ?>&f_user_id=<?php  p($f_user_id); ?>" ><IMG SRC="<?php echo $Campsite['ADMIN_IMAGE_BASE_URL']; ?>/add.png" BORDER="0"></A></TD>
			<TD><A HREF="add.php?f_subscription_id=<?php p($f_subscription_id); ?>&f_publication_id=<?php p($f_publication_id); ?>&f_user_id=<?php  p($f_user_id); ?>" ><B><?php  putGS("Add new section to subscription"); ?></B></A></TD>