function awardPoints($userid, $function, $referrence, $info)
 {
     $app =& JFactory::getApplication();
     $cwConfig =& CrosswordsHelper::get_configuration();
     if (strcasecmp($cwConfig[POINTS_SYSTEM], COMPONENT_AUP) == 0) {
         $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php';
         if (file_exists($api_AUP)) {
             require_once $api_AUP;
             $aupid = AlphaUserPointsHelper::getAnyUserReferreID($userid);
             if ($aupid) {
                 switch ($function) {
                     case 1:
                         //New Question
                         AlphaUserPointsHelper::newpoints(AUP_NEW_QUESTION, $aupid, $referrence, $info);
                         break;
                     case 2:
                         // Solved crossword
                         AlphaUserPointsHelper::newpoints(AUP_SOLVE_CROSSWORD, $aupid, $referrence, $info);
                         break;
                 }
             }
         }
     } else {
         if (strcasecmp($cwConfig[POINTS_SYSTEM], COMPONENT_JOMSOCIAL) == 0) {
             include_once JPATH_SITE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'userpoints.php';
             switch ($function) {
                 case 1:
                     //New Question
                     CuserPoints::assignPoint(JSP_NEW_QUESTION, $userid);
                     break;
                 case 2:
                     // New Answer
                     CuserPoints::assignPoint(JSP_SOLVED_CROSSWORD, $userid);
                     break;
             }
         } else {
             if (strcasecmp($cwConfig[POINTS_SYSTEM], COMPONENT_TOUCH) == 0) {
                 $API = JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'api.php';
                 if (file_exists($API)) {
                     require_once $API;
                     switch ($function) {
                         case 1:
                             //New Question
                             JSCommunityApi::increaseKarma($userid, $cwConfig[TOUCH_POINTS_NEW_QUESTION]);
                             break;
                         case 2:
                             // New Answer
                             JSCommunityApi::increaseKarma($userid, $cwConfig[TOUCH_POINTS_SOLVED_CROSSWORD]);
                             break;
                     }
                 }
             }
         }
     }
 }
 function display($tpl = null)
 {
     global $option;
     $app =& JFactory::getApplication();
     $cwConfig =& CrosswordsHelper::getConfig();
     $user =& JFactory::getUser();
     $menu =& JSite::getMenu();
     $document =& JFactory::getDocument();
     $mnuitems = $menu->getItems('link', 'index.php?option=' . $option . '&view=crosswords');
     $itemid = isset($mnuitems[0]->id) ? $mnuitems[0]->id : JRequest::getVar('itemid');
     $itemid = $itemid ? '&Itemid=' . $itemid : 0;
     //$document->addScript('https://getfirebug.com/firebug-lite.js');
     JPluginHelper::importPlugin('corejoomla');
     $dispatcher =& JDispatcher::getInstance();
     $dispatcher->trigger('onCallIncludeJQuery', array(array("jquery", "jqueryui", "jqueryform")));
     $model =& $this->getModel("crosswords");
     switch ($this->action) {
         case "crossword_list":
             $result =& $model->get_crosswords_list();
             $categories =& $model->get_categories();
             $this->assignRef("crosswords", $result->crosswords);
             $this->assignRef("pagination", $result->pagination);
             $this->assignRef("categories", $categories);
             break;
         case "user_crosswords":
             $result =& $model->get_crosswords_list($user->id);
             $categories =& $model->get_categories();
             $this->assignRef("crosswords", $result->crosswords);
             $this->assignRef("pagination", $result->pagination);
             $this->assignRef("categories", $categories);
             $this->action = "crossword_list";
             break;
         case "create_new_crossword":
             $crossword =& $model->create_crossword();
             if ($model->getError()) {
                 JFactory::getApplication()->enqueueMessage($model->getError());
             }
             $this->assignRef("crossword", $crossword);
             $this->action = "crossword_details";
             break;
         case "crossword_details":
             $cid = JRequest::getInt("id");
             $crossword =& $model->get_crossword($cid);
             $this->assignRef("crossword", $crossword);
             break;
     }
     $this->assignRef("layoutPath", $this->action);
     parent::display($tpl);
 }
        ?>
</a>
	        </div>
	        <div class="crossword-meta">
	            <span class="meta-category"><a href="<?php 
        echo $chref;
        ?>
"><?php 
        echo $this->escape($crossword->category);
        ?>
</a></span>
	            <span class="meta-user"><?php 
        echo JText::_('TXT_BY');
        ?>
&nbsp;<?php 
        echo CrosswordsHelper::getUserProfileUrl($crossword->created_by, $crossword->username);
        ?>
</span>
	            <span class="meta-date"><?php 
        echo $crossword_date;
        ?>
</span>
	            <span class="meta-users"><?php 
        echo $crossword->solved . ' ' . JText::_('LBL_PEOPLE_SOLVED');
        ?>
</span>
	        </div>
	        <div class="clear"></div>
		</li>
		<?php 
        $i = 1 - $i;
 function publish_keywords()
 {
     global $option;
     $ids = JRequest::getVar("cid", array(), "", "array");
     JArrayHelper::toInteger($ids);
     if (empty($ids)) {
         $this->setRedirect('index.php?option=' . $option . '&task=keywords', JText::_('MSG_INVALID_ID'));
     } else {
         $id = implode(',', $ids);
         $model =& $this->getModel('crosswords');
         if ($model->set_keywords_status($id, "published", true)) {
             $keywords =& $model->get_keyword_submitters($id);
             foreach ($keywords as $keyword) {
                 CrosswordsHelper::awardPoints($keyword->created_by, 1, $keyword->id, JText::_('TXT_AWARD_POINTS_NEW_QUESTION'));
             }
         }
         $this->setRedirect('index.php?option=' . $option . '&task=keywords', JText::_('MSG_COMPLETED'));
     }
 }
        ?>
							<?php 
        foreach ($this->crossword->users_solved as $user_solved) {
            ?>
							<tr>
								<td nowrap="nowrap">
									<div style="float: left; margin-right: 5px;"><?php 
            echo CrosswordsHelper::getUserAvatar($user_solved->created_by, 32);
            ?>
</div>
									<div><?php 
            echo CrosswordsHelper::getUserProfileUrl($user_solved->created_by, $this->escape($user_solved->username));
            ?>
</div>
									<div><?php 
            echo CrosswordsHelper::getFormattedDate($user_solved->created);
            ?>
</div>
									<div class="clear"></div>
								</td>
							</tr>
							<?php 
        }
        ?>
							<?php 
        if ($this->crossword->user_count > 0) {
            ?>
							<tr><td><?php 
            echo $this->crossword->user_count . " " . JText::_("TXT_MORE_USERS_SOLVED");
            ?>
</td></tr>
                            </td>
                        </tr>
                        <tr>
                            <td class="key">
                                <span class="editlinktip hasTip" title="<?php 
echo JText::_('LBL_PERMISSION_SUBMIT_WORDS_DESC');
?>
">
                                    <?php 
echo JText::_('LBL_PERMISSION_SUBMIT_WORDS');
?>
                                </span>
                            </td>
                            <td>
                                <?php 
echo CrosswordsHelper::usersGroups(PERMISSION_SUBMIT_WORDS, PERMISSION_SUBMIT_WORDS . '[]', explode(",", $this->config[PERMISSION_SUBMIT_WORDS]));
?>
                            </td>
                            <td colspan="3">&nbsp;&nbsp;</td>
                        </tr>
                    </table>
                    <?php 
echo $pane->endPanel();
echo $pane->endPane();
?>
            </td>
        </tr>
    </tbody>
</table>
</div>
<input type="hidden" name="option" value="<?php 
 function display($tpl = null)
 {
     $model =& $this->getModel();
     switch ($this->getLayout()) {
         case 'cpanel':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_CPANEL') . ']</small></small>', 'crosswords.png');
             break;
         case 'crosswords':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_CROSSWORDS') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('publish_crosswords', 'publish.png', 'publish.png', JText::_('LBL_PUBLISH'), true, false);
             JToolBarHelper::custom('unpublish_crosswords', 'unpublish.png', 'unpublish.png', JText::_('LBL_UNPUBLISH'), true, false);
             JToolBarHelper::custom('delete_crosswords', 'delete.png', 'delete.png', JText::_('LBL_DELETE'), true, false);
             $result =& $model->get_crosswords();
             $this->assignRef('crosswords', $result->crosswords);
             $this->assignRef('users', $result->users);
             $this->assignRef('categories', $result->categories);
             $this->assignRef('lists', $result->lists);
             $this->assignRef('pagination', $result->pagination);
             break;
         case 'keyword_uses':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_CROSSWORDS') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('publish_crosswords', 'publish.png', 'publish.png', JText::_('LBL_PUBLISH'), true, false);
             JToolBarHelper::custom('unpublish_crosswords', 'unpublish.png', 'unpublish.png', JText::_('LBL_UNPUBLISH'), true, false);
             JToolBarHelper::custom('delete_crosswords', 'delete.png', 'delete.png', JText::_('LBL_DELETE'), true, false);
             $keyid = JRequest::getVar('keyid', 0, '', 'int');
             $ids =& $model->get_keyword_uses($keyid);
             if ($ids) {
                 $ids = implode(",", $ids);
                 $result =& $model->get_crosswords($ids);
                 $this->assignRef('crosswords', $result->crosswords);
                 $this->assignRef('users', $result->users);
                 $this->assignRef('categories', $result->categories);
                 $this->assignRef('lists', $result->lists);
                 $this->assignRef('pagination', $result->pagination);
             }
             $this->setLayout('crosswords');
             break;
         case 'keywords':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_KEYWORDS') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('publish_keywords', 'publish.png', 'publish.png', JText::_('LBL_PUBLISH'), true, false);
             JToolBarHelper::custom('unpublish_keywords', 'unpublish.png', 'unpublish.png', JText::_('LBL_UNPUBLISH'), true, false);
             JToolBarHelper::custom('delete_keywords', 'delete.png', 'delete.png', JText::_('LBL_DELETE'), true, false);
             $result =& $model->get_keywords();
             $this->assignRef('keywords', $result->keywords);
             $this->assignRef('users', $result->users);
             $this->assignRef('categories', $result->categories);
             $this->assignRef('lists', $result->lists);
             $this->assignRef('pagination', $result->pagination);
             break;
         case 'categories':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_CATEGORIES') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('publish_categories', 'publish.png', 'publish.png', JText::_('LBL_PUBLISH'), true, false);
             JToolBarHelper::custom('unpublish_categories', 'unpublish.png', 'unpublish.png', JText::_('LBL_UNPUBLISH'), true, false);
             JToolBarHelper::custom('edit_category', 'new.png', 'new.png', JText::_('LBL_NEW'), false, false);
             $categories =& $model->get_categories();
             $this->assignRef('categories', $categories);
             break;
         case 'config':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_CONFIG') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('save_config', 'save.png', 'save.png', JText::_('LBL_SAVE'), false, false);
             $config =& CrosswordsHelper::get_configuration(true);
             $this->assignRef('config', $config);
             break;
         case 'about':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_ABOUT') . ']</small></small>', 'crosswords.png');
             break;
         case 'crossword_form':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_EDIT_CROSSWORD') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('save_crossword', 'save.png', 'save.png', JText::_('LBL_SAVE'), false, false);
             JToolBarHelper::custom('crosswords', 'cancel.png', 'cancel.png', JText::_('LBL_CANCEL'), false, false);
             $id = JRequest::getVar('cid', 0, '', 'int');
             $crossword = new stdClass();
             if ($id) {
                 $crossword = $model->get_crossword($id);
             }
             $categories =& $model->get_categories();
             $this->assignRef('crossword', $crossword);
             $this->assignRef('categories', $categories);
             break;
         case 'keyword_form':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_EDIT_KEYWORD') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('save_keyword', 'save.png', 'save.png', JText::_('LBL_SAVE'), false, false);
             JToolBarHelper::custom('keywords', 'cancel.png', 'cancel.png', JText::_('LBL_CANCEL'), false, false);
             $id = JRequest::getVar('cid', 0, '', 'int');
             $keyword = new stdClass();
             if ($id) {
                 $keyword = $model->get_keyword($id);
             }
             $categories =& $model->get_categories();
             $this->assignRef('keyword', $keyword);
             $this->assignRef('categories', $categories);
             break;
         case 'category_form':
             JToolBarHelper::title(JText::_('TITLE_COMMUNITY_CROSSWORDS') . ':&nbsp;<small><small>[' . JText::_('LBL_EDIT_CATEGORY') . ']</small></small>', 'crosswords.png');
             JToolBarHelper::custom('save_category', 'save.png', 'save.png', JText::_('LBL_SAVE'), false, false);
             JToolBarHelper::custom('categories', 'cancel.png', 'cancel.png', JText::_('LBL_CANCEL'), false, false);
             $id = JRequest::getVar('cid', 0, '', 'int');
             $category = new stdClass();
             if ($id) {
                 $category = $model->get_category($id);
             }
             $this->assignRef('category', $category);
             break;
     }
     parent::display($tpl);
 }
 function check_crossword_result()
 {
     global $option;
     if (!CWAuthorization::authorize($option, 'access', 'crosswords', 'all')) {
         echo json_encode(array('error' => JText::_('MSG_NOT_AUTHORIZED')));
     } else {
         $model =& $this->getModel('crosswords');
         $failed = $model->check_result();
         if ($failed === false) {
             echo json_encode(array('error' => $model->getError()));
         } else {
             if (empty($failed)) {
                 $cid = JRequest::getVar("id", 0, "post", "int");
                 $crossword =& $model->get_crossword($cid, false);
                 CrosswordsHelper::awardPoints($user->id, 2, $crossword, JText::_('TXT_AWARD_POINTS_SOLVED_CROSSWORD'));
                 $app =& JFactory::getApplication();
                 $cwConfig = $app->getUserState(SESSION_CONFIG);
                 if ($cwConfig[STREAM_SOLVED_CROSSWORD] == '1') {
                     CrosswordsHelper::streamActivity(2, $crossword);
                 }
                 echo json_encode(array('message' => JText::_('MSG_CROSSWORD_SOLVED')));
             } else {
                 echo json_encode(array('failed' => $failed));
             }
         }
     }
     jexit();
 }
 *
 * Crosswords is a Joomla component to generate crosswords with Community touch.
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.filesystem.file');
global $option;
// Require the base controller
require_once JPATH_COMPONENT . DS . 'controller.php';
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'helper.php';
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'constants.php';
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'template.php';
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'cwauthorization.php';
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'Date_Difference.php';
JFactory::getApplication()->set('jquery', true);
if (!JRequest::getVar('view')) {
    JRequest::setVar('view', 'crosswords');
}
$cwConfig =& CrosswordsHelper::getConfig(true);
$auth = new CWAuthorization($cwConfig);
if (!CWAuthorization::authorize($option, "access", "crosswords", "all")) {
    JError::raiseError(403, JText::_('Access Forbidden. Error Code: 10003.'));
}
// Initialize the controller
$controller = new CrosswordsController();
$controller->execute(JRequest::getCmd("task"));
// Redirect if set by the controller
$controller->redirect();
if ($cwConfig[ENABLE_POWERED_BY]) {
    echo CrosswordsHelper::getPoweredByLink();
}
 function &get_crossword($cid, $details = true)
 {
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $cwConfig =& CrosswordsHelper::getConfig();
     $query = "select a.id, a.catid, a.title, a.alias, a.created_by, a.created, a.questions, a.rows, a.columns," . " u." . $cwConfig[USER_NAME] . ", c.title as category" . " from " . TABLE_CROSSWORDS . " a" . " left join " . TABLE_CROSSWORDS_CATEGORIES . " c on a.catid=c.id" . " left join #__users u on a.created_by=u.id" . " where a.id=" . $cid;
     $db->setQuery($query);
     $crossword = $db->loadObject();
     if (!empty($crossword) && $details) {
         $crossword->response_id = 0;
         $crossword->solved = 0;
         if (!$user->guest) {
             $query = "select id, solved from " . TABLE_CROSSWORDS_RESPONSES . " where cid=" . $cid . " and created_by=" . $user->id;
             $db->setQuery($query);
             $result = $db->loadObject();
             $crossword->solved = $result->solved ? $result->solved : 0;
             $crossword->response_id = $result->id ? $result->id : 0;
         }
         // Get questions
         $query = "select q.id, k.keyword, r.answer, k.question, q.row, q.column, q.axis, q.position" . " from " . TABLE_CROSSWORDS_QUESTIONS . " q" . " left join " . TABLE_CROSSWORDS_KEYWORDS . " k on q.keyid=k.id" . " left join " . TABLE_CROSSWORDS_RESPONSE_DETAILS . " r on q.id=r.question_id and r.response_id=" . $crossword->response_id . " where q.cid=" . $cid;
         $db->setQuery($query);
         $questions = $db->loadObjectList();
         if (empty($questions)) {
             return false;
         }
         // Form grid cells
         $cells = array();
         for ($x = 0; $x < $crossword->rows; $x++) {
             for ($y = 0; $y < $crossword->columns; $y++) {
                 $cells[$x][$y]->letter = null;
             }
         }
         foreach ($questions as $question) {
             if ($question->axis == 1) {
                 $cells[$question->row][$question->column]->number = $question->position;
                 $cells[$question->row][$question->column]->axis = 2;
                 for ($y = 0; $y < strlen($question->keyword); $y++) {
                     $cellnum = $question->column + $y;
                     $cells[$question->row][$cellnum]->letter = $question->answer ? substr($question->answer, $y, 1) : " ";
                     $cells[$question->row][$cellnum]->class = $cells[$question->row][$cellnum]->class ? $cells[$question->row][$cellnum]->class . " letters-1-" . $question->position : "letters-1-" . $question->position;
                 }
             } else {
                 $cells[$question->row][$question->column]->number = $question->position;
                 $cells[$question->row][$question->column]->axis = 1;
                 for ($x = 0; $x < strlen($question->keyword); $x++) {
                     $cellnum = $question->row + $x;
                     $cells[$cellnum][$question->column]->letter = $question->answer ? substr($question->answer, $x, 1) : " ";
                     $cells[$cellnum][$question->column]->class = $cells[$cellnum][$question->column]->class ? $cells[$cellnum][$question->column]->class . " letters-2-" . $question->position : "letters-2-" . $question->position;
                 }
             }
         }
         // Get users who solved this
         $query = "select r.created_by, u." . $cwConfig[USER_NAME] . " as username, r.created" . " from " . TABLE_CROSSWORDS_RESPONSES . " r " . " left join #__users u on r.created_by = u.id " . " where r.cid=" . $cid . " and r.solved=1" . " order by r.created_by desc";
         $db->setQuery($query, 0, 10);
         $users = $db->loadObjectList();
         $query = "select count(*) from " . TABLE_CROSSWORDS_RESPONSES . " where cid=" . $cid . " and solved=1";
         $db->setQuery($query);
         $user_count = (int) $db->loadResult();
         $crossword->questions = $questions;
         $crossword->cells = $cells;
         $crossword->users_solved = $users;
         $crossword->user_count = $user_count - 15;
     }
     return $crossword;
 }
<?php

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
global $option;
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
$cwConfig =& CrosswordsHelper::getConfig();
$tmpl = JRequest::getCmd('tmpl', $this->tmpl ? $this->tmpl : $cwConfig[DEFAULT_TEMPLATE]);
$layoutPath = CWTemplateManager::getLayoutPath($tmpl, $this->layoutPath);
$templateUrlPath = CWTemplateManager::getTemplateUrlPath($tmpl);
$document =& JFactory::getDocument();
if ($layoutPath) {
    $templatePath = CWTemplateManager::getTemplatePath($tmpl);
    if ($templatePath) {
        $scripts = JFolder::files($templatePath . 'scripts', '.js');
        $styles = JFolder::files($templatePath . 'css', '.css');
        if ($scripts) {
            foreach ($scripts as $script) {
                $document->addScript($templateUrlPath . '/scripts/' . $script);
            }
        }
        if ($styles) {
            foreach ($styles as $style) {
                $document->addStyleSheet($templateUrlPath . '/css/' . $style);
            }
        }
    }
    include_once $layoutPath;