Location: PHPKode > projects > PhpChrystal - An Open Intranet System > 0.071Alpha1/phpVoting.php
<?php
  session_start();
  session_set_cookie_params(32758);

  // XML::MODUL   (phpVoting)
  // XML::VERSION (0.071 Alpha1)
  // XML::AUTHOR  (::[CTH]Goldenhawk::)
  // XML::INFO    (phpVoting erstellt das Votingmenu, fügt Votings ein etc.)


  // XML::COMMENT (Vesrion, Name und Autor festlege)
  $PLUGIN_VERSION = "0.071 Alpha1";
  $PLUGIN_NAME    = "phpVoting";
  $PLUGIN_AUTHOR  = "::[CTH]Goldenhawk::";

  // XML::COMMENT (Variablen laden)
  include_once("./classes/CCore.php");

  // XML::FUNC::getInfo ($self->getInfo())
  // XML::DESC::getInfo (liefert Name, Autor und Version des Modules zurück)
  // XML::VERSION::getInfo  (1.0)
  // XML::RETURN::getInfo ($PLUGIN_NAME,$PLUGIN_AUTHOR,$PLUGIN_VERSION)
  function getInfo()
  {
    global $PLUGIN_VERSION,$PLUGIN_NAME,$PLUGIN_AUTHOR;

    return $PLUGIN_NAME;
    return $PLUGIN_AUTHOR;
    return $PLUGIN_VERSION;
  }

  // XML::COMMENT (Template initalisieren)
  $cdesign->initalizeTemplate($arNoOpts);
  
  // XML::COMMENT (-----------------------------)
  // XML::COMMENT (------ Ausgaberoutinen ------)
  // XML::COMMENT (-----------------------------)

  if ($_GET['cmd'] == 'show_votings')
  {
    if (!$refid)
    {
      $desTop[0][text] = $cxml->printString($lang['show.votings.subject.vote']);
      $desTop[1][text] = $cxml->printString($lang['show.votings.subject.status']);
      $desTop[2][text] = $cxml->printString($lang['show.votings.subject.voted']);
      $cl->cellsTop($desTop);

      $arVotes = $cvote->getVoting($arNoOpts);

	  for ($cnt = 0;$cnt<count($arVotes);$cnt++)
	  {
	    $desText[0][text] = "<a href=\"$PHP_SELF?cmd=show_votings&amp;refid=".$arVotes[$cnt][id]."\">".$arVotes[$cnt][szQuestion]."</a>";
	    ($arVotes[$cnt][bIsOpened]) ? ($m_out = $cxml->printString($lang['ar.1.opened'])) : ($m_out = $cxml->printString($lang['ar.1.closed']));
	    $desText[1][text] = $m_out;
	    $desText[2][text] = $cvote->getTotalVotes($arVotes[$cnt][id]);
	    $cl->TableText($desText);
	  }

	  (!$arVotes) ? ($cl->cellsTop(array(array('text' => $cxml->printString($lang['message.no_entries']), 'colspan' => 3)))) : ($dummy);
	}
	else
	{
	  $cl->FormNew("$PHP_SELF?cmd=show_votings&amp;refid=$refid&amp;what=add","");

	  (!$refid) ? ($cfunc->faultExt($cxml->printString($lang['fault.no_vid']))) : ($dummy);

	  // XML::COMMENT (Voting neu laden)
	  $arQuestion = $cvote->getVoting(array('id' => $refid));

	  if ($_GET['what'] == 'add')
	  {
        if (!$in_id)
          $szFault = "fault.no_id";

        if (!$arQuestion[0][bIsOpened])
          $szFault = "fault.vote_is_closed";

	    if ($arQuestion[0][bAllowVoteOnlyRegisteredMembers] && !$_SESSION['active_userlogin'])
	      $szFault = "fault.not_logged_in";

	    if (!$arQuestion[0][bAllowMultivote] && $_SESSION['bVotedFor_id_'.$refid])
	      $szFault = "fault.no_multivote";

	    if (!$szFault)
	    {
	      $cvote->incVoting($in_id,$refid);

	      // XML::COMMENT (ID des Votings in der Session speichern, für Multivoteoption)
	      $_SESSION["bVotedFor_id_".$refid] = $refid;
		  // ${"bVotedFor_id_".$refid} = $refid;
		  // session_register("bVotedFor_id_$refid");
	    }
	  }


	  $desTop[0][colspan] = 3;
	  $desTop[0][text]    = $cxml->printString($lang['userupdate.subject'],$arQuestion[0][szQuestion],$cvote->getTotalVotes($refid));
	  $cl->cellsTop($desTop);

	  $design['diag.color.front'] = urlencode($design['diag.color.front']);
	  $design['diag.color.bg']    = urlencode($design['diag.color.bg']);
	  $m_url = "width=100&amp;bgc=".$design['diag.color.bg']."&amp;fc=".$design['diag.color.front']."&amp;vhp=".$cvote->getTotalVotes($refid)."&amp;height=10";

	  $arAnswers = $cvote->getAnswers(array('iRefID' => $refid));

	  for($cnt=0;$cnt<count($arAnswers);$cnt++)
	  {
	    $cnt2 = $cnt;
	    $cnt2++;
	    $desText[0][text] = $cl->createInput(array('type' => 'radio', 'name' => 'in_id', 'value' => $arAnswers[$cnt][id]));
	    $desText[1][text] = $arAnswers[$cnt][szAnswer]." (".$arAnswers[$cnt][iVoted].")";
	    $desText[2][text] = "<img title=\"".$cxml->printString($lang['userupdate.image.title'])."\" alt=\"".$cxml->printString($lang['userupdate.image.title'])."\" src=\"phpContainer.php?func=rpc_render_diag&amp;vdone=".$arAnswers[$cnt][iVoted]."&amp;".$m_url."\" />";
	    $cl->TableText($desText);
	    unset($desText);
	  }

	  if ($cnt)
	    $cl->FormSubmit("3",$cxml->printString($lang['show.votings.form']),"out");

	  $cl->TableText(array(array('colspan' => 3, 'p_class' => 'center', 'text' => "<a href=\"$PHP_SELF?cmd=show_votings\">".$cxml->printString($lang['userupdate.link.show_all_votings'])."</a>")));

	  if ($szFault)
	    $cl->TableText(array(array('colspan' => 3, 'p_class' => 'center', 'text' => $cxml->printString($lang[$szFault]))));
	}
  }
  elseif ($_GET['cmd'] == 'admin_overview')
  {
    (!$csecure->verifyUserForAdminArea(array('iUserID' => $_SESSION['active_userid'], 'area' => $PLUGIN_NAME))) ? ($cfunc->faultExt($cxml->printString($lang_def['fault.not_authorized']))) : ($dummy);
    $cl->FormNew("$PHP_SELF?cmd=cmd_update&amp;what=add","");

	$cl->cells2Noopt($cxml->printString($lang['admin.add.question']),$cl->createInput(array('name' => "in_subject")),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.active']),$cl->createInput(array('name' => "in_active", 'type' => 'checkbox')),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.opened']),$cl->createInput(array('name' => "in_opened", 'type' => 'checkbox', 'checked' => 1)),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.show_result_link']),$cl->createInput(array('name' => "in_result_link", 'type' => 'checkbox', 'checked' => 1)),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.show_total_votings']),$cl->createInput(array('name' => "in_total_votings", 'type' => 'checkbox', 'checked' => 1)),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.allow_multivote']),$cl->createInput(array('name' => "in_allow_multivote", 'type' => 'checkbox', 'checked' => 1)),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.only_registered']),$cl->createInput(array('name' => "in_only_registered", 'type' => 'checkbox', 'checked' => 1)),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.answers']),$cl->createTextArea($arNoOpts),"out");
    $cl->FormSubmit("2",$cxml->printString($lang['admin.add.form']));
  }
  elseif ($_GET['cmd'] == 'admin_edit')
  {
    (!$csecure->verifyUserForAdminArea(array('iUserID' => $_SESSION['active_userid'], 'area' => $PLUGIN_NAME))) ? ($cfunc->faultExt($cxml->printString($lang_def['fault.not_authorized']))) : ($dummy);
    $cl->FormNew("$PHP_SELF?cmd=cmd_update&amp;what=votings","");

	$desTop[0][text] = $cxml->printString($lang['admin.edit.subject.delete']);
	$desTop[1][text] = $cxml->printString($lang['admin.edit.subject.active']);
	$desTop[2][text] = $cxml->printString($lang['admin.edit.subject.opened']);
	$desTop[3][text] = $cxml->printString($lang['admin.edit.subject.voting']);
	$cl->cellsTop($desTop);

	$arVotings = $cvote->getVoting($arNoOpts);

	for ($cnt = 0;$cnt<count($arVotings);$cnt++)
	{
	  $cl->FormHidden("in_ids[]",$arVotings[$cnt][id]);
	  $desText[0][text] = $cl->createInput(array('type' => 'checkbox', 'name' => 'in_todel[]', 'value' => $arVotings[$cnt][id]));

	  ($arVotings[$cnt][bIsVisible]) ? ($checked = "checked") : ($checked = "");
	  $desText[1][text] = $cl->createInput(array('type' => 'checkbox', 'name' => 'in_active'.$arVotings[$cnt][id], 'checked' => $checked));

	  ($arVotings[$cnt][bIsOpened]) ? ($checked = "checked") : ($checked = "");
	  $desText[2][text] = $cl->createInput(array('type' => 'checkbox', 'name' => 'in_opened'.$arVotings[$cnt][id], 'checked' => $checked));

	  $desText[3][text] = "<a href = \"$PHP_SELF?cmd=admin_change&id=".$arVotings[$cnt][id]."\">".$arVotings[$cnt][szQuestion]."</a>";

	  $cl->TableText($desText);
    }

	(!$cnt) ? ($cl->cellsTop(array(array('colspan' => '4', 'text' => $cxml->printString($lang['message.no_entries']))))) : ($cl->FormSubmit("4",$cxml->printString($lang['admin.votings.form'])));
  }
  elseif ($_GET['cmd'] == 'admin_change')
  {
    (!$csecure->verifyUserForAdminArea(array('iUserID' => $_SESSION['active_userid'], 'area' => $PLUGIN_NAME))) ? ($cfunc->faultExt($cxml->printString($lang_def['fault.not_authorized']))) : ($dummy);

    $cl->FormNew("$PHP_SELF?cmd=cmd_update&amp;what=change&id=$id","");
	$arVote = $cvote->getVoting(array('id' => $id));

	$cl->cellsTop(array(array('colspan' => 2, 'text' => $cxml->printString($lang['admin.change.subject'],$arVote[0][szQuestion],$_GET['id']))));
	$cl->cells2Noopt($cxml->printString($lang['admin.add.question']),$cl->createInput(array('name' => "in_subject", value => $arVote[0][szQuestion])),"out");
	($arVote[0][bIsVisible]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.active']),$cl->createInput(array('name' => "in_active", 'type' => 'checkbox', 'checked' => $checked)),"out");
	($arVote[0][bIsOpened]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.opened']),$cl->createInput(array('name' => "in_opened", 'type' => 'checkbox', 'checked' => $checked)),"out");
	($arVote[0][bShowResultLink]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.show_result_link']),$cl->createInput(array('name' => "in_result_link", 'type' => 'checkbox', 'checked' => $checked)),"out");
	($arVote[0][bShowTotalVotings]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.show_total_votings']),$cl->createInput(array('name' => "in_total_votings", 'type' => 'checkbox', 'checked' => $checked)),"out");
	($arVote[0][bAllowMultivote]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.allow_multivote']),$cl->createInput(array('name' => "in_allow_multivote", 'type' => 'checkbox', 'checked' => $checked)),"out");
	($arVote[0][bAllowVoteOnlyRegisteredMembers]) ? ($checked = "checked") : ($checked = "");
	$cl->cells2Noopt($cxml->printString($lang['admin.add.only_registered']),$cl->createInput(array('name' => "in_only_registered", 'type' => 'checkbox', 'checked' => $checked)),"out");

	$arAnswers = $cvote->getAnswers(array('iRefID' => $id));
	for ($cnt = 0;$cnt<count($arAnswers);$cnt++)
	{
	  $cl->FormHidden("in_ids[]",$arAnswers[$cnt][id]);
	  $cl->cells2Noopt($cxml->printString($lang['admin.change.delete'],$arAnswers[$cnt][szAnswer]),$cl->createInput(array('name' => $arAnswers[$cnt][id]."delete", 'type' => 'checkbox')),"out");
	}

	$cl->cells2Noopt($cxml->printString($lang['admin.change.reset']),$cl->createInput(array('name' => "in_reset", 'type' => 'checkbox')),"out");
	$cl->cells2Noopt($cxml->printString($lang['admin.change.answers']),$cl->createTextArea($arNoOpts),"out");
    $cl->FormSubmit("2",$cxml->printString($lang['admin.add.form']));
  }
  // XML::COMMENT (Einstellugnen übernehmen)
  elseif ($_GET['cmd'] == 'cmd_update')
  {
    (!$csecure->verifyUserForAdminArea(array('iUserID' => $_SESSION['active_userid'], 'area' => $PLUGIN_NAME))) ? ($cfunc->faultExt($cxml->printString($lang_def['fault.not_authorized']))) : ($dummy);

	if ($_GET['what'] == 'add')
	{
	  $cvote->addVoting(array('szQuestion' => $in_subject, 'bIsVisible' => $in_active, 'bIsOpened' => $in_opened, 'bShowResultLink' => $in_result_link, 'bShowTotalVotings' => $in_total_votings, 'bAllowMultiVote' => $in_allow_multivote, 'bAllowVoteOnlyRegisteredMembers' => $in_only_registered, 'szAnswers' => $in_body));
	}
	elseif ($_GET['what'] == 'votings')
	{
	  for ($cnt = 0;$cnt<count($in_todel);$cnt++)
	    $cvote->deleteVoting($in_todel[$cnt]);

	  for ($cnt = 0;$cnt<count($in_ids);$cnt++)
	    $cvote->setAnswer(array('id' => $in_ids[$cnt], 'bIsVisible' => ${'in_active'.$in_ids[$cnt]}, 'bIsOpened' => ${'in_opened'.$in_ids[$cnt]}));
	}
	elseif ($_GET['what'] == 'change')
	{
	  (!$id) ? ($cfunc->faultExt($cxml->printString($lang_def['fault.missing.id']))) : ($dummy);

	  $cvote->setAnswer(array('id' => $id, 'szQuestion' => $in_subject, 'bIsVisible' => $in_active, 'bIsOpened' => $in_opened, 'bShowResultLink' => $in_result_link, 'bShowTotalVotings' => $in_total_votings, 'bAllowMultiVote' => $in_allow_multivote, 'bAllowVoteOnlyRegisteredMembers' => $in_only_registered));
	  $cvote->addAnswers(array('iRefID' => $id, 'szAnswers' => $in_body));

	  if ($in_reset)
	    $cvote->resetAnswers(array('id' => $id));

	  for ($cnt = 0;$cnt<count($in_ids);$cnt++)
	    if (${$in_ids[$cnt]."delete"})
	      $cvote->deleteAnswer(array('id' => $in_ids[$cnt]));
	}
	printDanke();
  }
  else
  {
    faultExt($cxml->printString($lang_def['fault.not_registered']));
  }

  // XML::COMMENT (Seite abschließen)
  $cdesign->createSiteFooter($arOpts);
?>
Return current item: PhpChrystal - An Open Intranet System