Advertisement
Guest User

advinvsys.php

a guest
Apr 30th, 2014
1,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 86.74 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.   @author     : Surdeanu Mihai ;
  5.   @date       : 8 august 2012 ;
  6.   @version    : 1.1.1 ;
  7.   @mybb       : compatibilitate cu MyBB 1.6 (orice versiuni) ;
  8.   @description: Modificare permite introducerea unui sistem de invitatii pe forumul tau!
  9.   @homepage   : http://mybb.ro ! Te rugam sa ne vizitezi pentru ca nu ai ce pierde!
  10.   @copyright  : Licenta speciala. Pentru mai multe detalii te rugam sa citesti sectiunea Licenta din cadrul fisierului
  11.   ReadME.pdf care poate fi gasit in acest pachet. Iti multumim pentru intelegere!
  12.   ====================================
  13.   Ultima modificare a codului : 08.08.2012 14:36
  14.  */
  15.  
  16. // Poate fi accesat direct fisierul?
  17. if (!defined("IN_MYBB")) {
  18.     die("This file cannot be accessed directly.");
  19. }
  20.  
  21. // se incarca si fisierul prin care vedem ce versiune se foloseste
  22. require_once MYBB_ROOT . "inc/plugins/advinvsys/system_version.php";
  23.  
  24. // se incarca si fisierul cu clasa de dezvoltare
  25. require_once MYBB_ROOT . "inc/plugins/advinvsys/classes/class_develop.php";
  26.  
  27. global $AISDevelop;
  28. $AISDevelop = new AISDevelop();
  29.  
  30. // Carlige de legatura cu core-ul MyBB
  31. /* Interfata cu utilizatorul */
  32. $plugins->add_hook('global_start', 'advinvsys_plugins_start');
  33. $plugins->add_hook('datahandler_user_validate', 'advinvsys_user_validate');
  34. $plugins->add_hook('member_profile_end', 'advinvsys_profile');
  35. $plugins->add_hook('member_register_agreement', 'advinvsys_register_agreement');
  36. $plugins->add_hook('member_register_end', 'advinvsys_register_end');
  37. $plugins->add_hook('member_do_register_end', 'advinvsys_do_register');
  38. $plugins->add_hook('usercp_menu', 'advinvsys_menu_built', 30);
  39. $plugins->add_hook('usercp_start', 'advinvsys_main_page');
  40. $plugins->add_hook('stats_end', 'advinvsys_stats');
  41. $plugins->add_hook('xmlhttp', 'advinvsys_xmlhttp');
  42. /* Panoul de administrare */
  43. $plugins->add_hook('admin_load', 'advinvsys_admin_load_hook');
  44. $plugins->add_hook("admin_config_menu", "advinvsys_admin_menu");
  45. $plugins->add_hook("admin_config_action_handler", "advinvsys_admin_action_handler");
  46. $plugins->add_hook("admin_user_groups_edit_graph_tabs", "advinvsys_admin_groups_edit_tab");
  47. $plugins->add_hook("admin_user_groups_edit_graph", "advinvsys_admin_groups_edit");
  48. $plugins->add_hook("admin_user_groups_edit_commit", "advinvsys_admin_groups_edit_save");
  49.  
  50. // se incarca si fisierul prin care se acorda credite
  51. require_once MYBB_ROOT . "inc/plugins/advinvsys/function_credits.php";
  52.  
  53. // Informatii legate de modificare
  54. function advinvsys_info() {
  55.     global $db;
  56.    
  57.     $array = array(
  58.         "name"          => "Advanced Invitations System",
  59.         "description"   => "Based on a credit system and with a lot of powerful features this is the ultimate way to get more users in your forum.",
  60.         "website"       => "http://mybb.ro",
  61.         "author"        => "MyBB Rom&#226;nia Team",
  62.         "authorsite"    => "http://mybb.ro",
  63.         "version"       => AIS_VERSION,
  64.         "release"       => "08.08.2012",
  65.         "compatibility" => "16*"
  66.     );
  67.    
  68.     if (advinvsys_compare_version())
  69.         $array['description'] .= "<div style='float:right; color:green'>[PHP : " . PHP_VERSION ."; DB : {$db->type}]</div>";
  70.     else
  71.         $array['description'] .= "<div style='float:right; color:red'>[PHP : " . PHP_VERSION ."; DB : {$db->type}]</div>";
  72.        
  73.     return $array;
  74. }
  75.  
  76. // Functia verifica daca versiunea de PHP este cea buna...
  77. function advinvsys_compare_version() {
  78.     if (version_compare(PHP_VERSION, AIS_MIN_PHP) >= 0)
  79.         return true;
  80.     else
  81.         return false;
  82. }
  83.  
  84. // Functia de instalare a modificarii
  85. function advinvsys_install() {
  86.     global $db;
  87.    
  88.     // inainte de a crea eventuale tabele vom vedea ce colocatie avem...
  89.     $collation = $db->build_create_table_collation();
  90.    
  91.     // daca tabelul cu log-uri exista atunci nu se va mai crea
  92.     if (!$db->table_exists("advinvsys_codes")) {
  93.         // daca nu exista se purcede la crearea lui
  94.         $db->write_query("CREATE TABLE `" . TABLE_PREFIX . "advinvsys_codes` (
  95.            `cid` bigint(30) UNSIGNED NOT NULL auto_increment,
  96.            `did` bigint(30) UNSIGNED NOT NULL default '1',
  97.            `email` varchar(64) NOT NULL default '',
  98.            `code` varchar(32) NOT NULL default '',
  99.            `date` bigint(30) UNSIGNED NOT NULL default '0',
  100.            PRIMARY KEY  (`cid`), KEY(`code`)
  101.                ) ENGINE=MyISAM{$collation}");
  102.     }
  103.     if (!$db->table_exists("advinvsys_logs")) {
  104.         // daca nu exista se purcede la crearea lui
  105.         $db->write_query("CREATE TABLE `" . TABLE_PREFIX . "advinvsys_logs` (
  106.            `lid` bigint(30) UNSIGNED NOT NULL auto_increment,
  107.            `uid` bigint(30) UNSIGNED NOT NULL default '1',
  108.            `type` varchar(256) NOT NULL default '',
  109.            `data` TEXT NOT NULL,
  110.            `date` bigint(30) UNSIGNED NOT NULL default '0',
  111.            PRIMARY KEY  (`lid`), KEY(`date`)
  112.                ) ENGINE=MyISAM{$collation}");
  113.     }
  114.     if (!$db->table_exists("advinvsys_incomes")) {
  115.         $db->write_query("CREATE TABLE `" . TABLE_PREFIX . "advinvsys_incomes` (
  116.            `iid` bigint(30) UNSIGNED NOT NULL auto_increment,
  117.            `enabled` int(1) NOT NULL default '0',
  118.            `name` varchar(100) NOT NULL default '',
  119.            `type` varchar(64) NOT NULL default '',
  120.            `description` text NOT NULL,
  121.            `fid` text NOT NULL,
  122.            `gid` text NOT NULL,
  123.            `invitations` DECIMAL(30,2) UNSIGNED NOT NULL default '0',
  124.            `additional` DECIMAL(30,2) UNSIGNED NOT NULL default '0',    
  125.            PRIMARY KEY  (`iid`)
  126.                ) ENGINE=MyISAM{$collation}");
  127.     }
  128.    
  129.     // se mai adauga o noua coloana in tabela "users" din sistemul MyBB
  130.     if (!$db->field_exists('invitations', 'users')) {
  131.         // se va adauga doar daca campul nu exista in tabela
  132.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` ADD `invitations` DECIMAL(30,2) UNSIGNED NOT NULL default '0';");
  133.     }
  134.     if (!$db->field_exists('last_timeonline', 'users')) {
  135.         // se va adauga doar daca campul nu exista in tabela
  136.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` ADD `last_timeonline` bigint(30) UNSIGNED NOT NULL default '0';");
  137.     }
  138.     if (!$db->field_exists('invitation_refer', 'users')) {
  139.         // se va adauga doar daca campul nu exista in tabela
  140.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` ADD `invitation_refer` bigint(30) UNSIGNED NOT NULL default '0';");
  141.     }
  142.    
  143.     // se mai adauga o noua coloana in tabela "usergroups" din sistemul MyBB
  144.     if (!$db->field_exists('max_invitations', 'usergroups')) {
  145.         // se va adauga doar daca campul nu exista in tabela
  146.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "usergroups` ADD `max_invitations` DECIMAL(30,2) NOT NULL default '-1.00';");
  147.     }
  148.    
  149.    
  150.     // se creaza un set de sabloane in baza de date
  151.     $template_group = array(
  152.         'prefix' => 'advinvsys',
  153.         'title' => 'AIS'
  154.     );
  155.    
  156.     // grupul este adaugat in baza de date
  157.     $db->insert_query('templategroups', $template_group);
  158.    
  159.     // se adauga si eventualele sabloane ale modificarii   
  160.     $templates = advinvsys_get_templates();
  161.    
  162.     // pentru fiecare sablon din vector se realizeaza introducerea lui in baza de date 
  163.     foreach ($templates as $template) {
  164.         $insert = array(
  165.             "title" => $template['title'],
  166.             "template" => $db->escape_string($template['template']),
  167.             "sid" => "-2",
  168.             "version" => "1600",
  169.             "status" => "",
  170.             "dateline" => TIME_NOW
  171.         );
  172.         $db->insert_query("templates", $insert);
  173.     }
  174.    
  175.     // se creaza si un nou task
  176.     $new_task = array(
  177.         "title" => "Advanced Invitations System",
  178.         "description" => "Gives you the possibility to create automated tasks.",
  179.         "file" => "advinvsys_task",
  180.         "minute" => '0',
  181.         "hour" => '0',
  182.         "day" => '*',
  183.         "month" => '*',
  184.         "weekday" => '0',
  185.         "enabled" => '1',
  186.         "logging" => '1'
  187.     );
  188.     // va rula dupa 10 minute de la data adaugarii in sistem
  189.     $new_task['nextrun'] = intval(TIME_NOW + 600);
  190.    
  191.     $db->insert_query('tasks', $new_task);
  192. }
  193.  
  194. // Functia care verifica daca modificarea e instalata
  195. function advinvsys_is_installed() {
  196.     global $db;
  197.     // exista tabelele aplicatiei ?
  198.     return ($db->table_exists('advinvsys_codes') &&
  199.             $db->table_exists('advinvsys_logs')) ? true : false;
  200. }
  201.  
  202. // Functia prin care se dezinstaleaza o modificare
  203. function advinvsys_uninstall() {
  204.     global $db;
  205.    
  206.     // daca tabela "advinvsys_codes" exista in baza de date atunci se sterge!
  207.     if ($db->table_exists('advinvsys_codes')) {
  208.         $db->drop_table('advinvsys_codes');
  209.     }
  210.     if ($db->table_exists('advinvsys_logs')) {
  211.         $db->drop_table('advinvsys_logs');
  212.     }
  213.     if ($db->table_exists('advinvsys_incomes')) {
  214.         $db->drop_table('advinvsys_incomes');
  215.     }
  216.    
  217.     // se sterge coloana adaugata de modificare din tabela "users" ?
  218.     if ($db->field_exists('invitations', 'users')) {
  219.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` DROP `invitations`;");
  220.     }
  221.     if ($db->field_exists('last_timeonline', 'users')) {
  222.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` DROP `last_timeonline`;");
  223.     }
  224.     if ($db->field_exists('invitation_refer', 'users')) {
  225.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "users` DROP `invitation_refer`;");
  226.     }
  227.     // se sterge coloana adaugata de modificare din tabela "usergroups " ?
  228.     if ($db->field_exists('max_invitations', 'usergroups')) {
  229.         $db->write_query("ALTER TABLE `" . TABLE_PREFIX . "usergroups` DROP `max_invitations`;");
  230.     }
  231.    
  232.     // se sterge grupul de sabloane
  233.     $db->delete_query("templategroups", "prefix = 'advinvsys'");
  234.     // se sterg sabloanele din baza de date
  235.     $db->delete_query("templates", "title LIKE 'advinvsys_%'");
  236.     // se sterge task-ul din sistem
  237.     $db->delete_query("tasks", "file = 'advinvsys_task'");
  238. }
  239.  
  240. // Functia de activare a modificarii
  241. function advinvsys_activate() {
  242.     global $mybb, $db, $AISDevelop;
  243.    
  244.     // se creaza grupul de setari
  245.     $group = array(
  246.         "gid" => "NULL",
  247.         "name" => "advinvsys_group",
  248.         "title" => "Advanced Invitations System",
  249.         "description" => "Settings for the \"Advanced Invitations System\" plugin.",
  250.         "disporder" => "1",
  251.         "isdefault" => "no",
  252.     );
  253.     $db->insert_query("settinggroups", $group);
  254.     $gid = $db->insert_id();
  255.    
  256.     // se creaza vectorul de setari ale modificarii
  257.     $settings = advinvsys_get_settings(array());
  258.    
  259.     $AISDevelop->addSettings('', $settings, $gid, $AISDevelop::DISPLAY_ORDER_BEGIN);
  260.    
  261.     // se adauga campul de verificare al codului invitatiei in cadrul formularului de inregistrare
  262.     require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
  263.     find_replace_templatesets("member_profile", '#' . preg_quote('{$warning_level}') . '#i', '{$warning_level}{$advinvsys_profile}');
  264.     find_replace_templatesets("member_register", "#" . preg_quote('{$regimage}') . "#i", '{$advinvsys_reg_field}{$regimage}');
  265.     find_replace_templatesets("member_register_agreement", "#" . preg_quote('<input type="hidden" name="action" value="register" />') . "#i", '<input type="hidden" name="action" value="register" />{$advinvsys_save_code}');
  266.     find_replace_templatesets("stats", "#" . preg_quote('<strong>{$stats[\'numusers\']}</strong>') . "#i", '<strong>{$stats[\'numusers\']}</strong><br />{$lang->advinvsys_stats_total} <strong>{$stats[\'totalinvs\']}</strong>');
  267.     find_replace_templatesets("stats", "#" . preg_quote('<strong>{$repliesperthread}</strong>') . "#i", '<strong>{$repliesperthread}</strong><br />{$lang->advinvsys_stats_perusers} <strong>{$advinvsys_invsperusers}</strong>');
  268. }
  269.  
  270. // Functia de dezactivare a modificarii
  271. function advinvsys_deactivate() {
  272.     global $db;
  273.    
  274.     // se sterg setarile din baza de date
  275.     $db->write_query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name = 'advinvsys_group'");
  276.     $db->write_query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name LIKE 'advinvsys_setting_%'");
  277.    
  278.     // se reconstruiesc toate setarile
  279.     rebuild_settings();
  280.    
  281.     // se sterge cache-ul folosit la reguli
  282.     $db->delete_query("datacache", "title = 'advinvsys_rules'");
  283.    
  284.     // se sterge campul de verificare al codului invitatiei in cadrul formularului de inregistrare
  285.     require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
  286.     find_replace_templatesets("member_profile", '#' . preg_quote('{$advinvsys_profile}') . '#i', '', 0);
  287.     find_replace_templatesets("member_register", "#" . preg_quote('{$advinvsys_reg_field}') . "#i", '', 0);
  288.     find_replace_templatesets("member_register_agreement", "#" . preg_quote('{$advinvsys_save_code}') . "#i", '', 0);
  289.     find_replace_templatesets("stats", "#" . preg_quote('<br />{$lang->advinvsys_stats_total} <strong>{$stats[\'totalinvs\']}</strong>') . "#i", '', 0);      
  290.     find_replace_templatesets("stats", "#" . preg_quote('<br />{$lang->advinvsys_stats_perusers} <strong>{$advinvsys_invsperusers}</strong>') . "#i", '', 0);
  291. }
  292.  
  293. // Functia intoarce un vector cu sabloanele ce vor fi instalate
  294. function advinvsys_get_templates($ids = array())
  295. {
  296.     $templates = array();
  297.     $templates[] = array(
  298.         'title' => 'advinvsys_donate_header',
  299.         'template' => '<script type="text/javascript" src="../jscripts/scriptaculous.js?load=effects"></script>
  300.        <script type="text/javascript">
  301.            Event.observe(document, "dom:loaded", function() {
  302.                $(\'amount\').observe(\'change\', function() {
  303.                    var value = this.getValue();
  304.                    if (value.match(/^\d{1,9}(\.\d{1,2})?$/))
  305.                        this.setStyle({ background: \'#BCF5A9\' });
  306.                    else
  307.                        this.setStyle({ background: \'#F5A9BC\' });
  308.                });
  309.            });
  310.        </script>'
  311.     );
  312.     $templates[] = array(
  313.         'title' => 'advinvsys_preview_header',
  314.         'template' => '<link type="text/css" rel="stylesheet" href="./inc/plugins/advinvsys/classes/style_table.css" />
  315.        <style type="text/css">
  316.            a.advinvsys_send_button {
  317.                display: block; height: 16px; width: 16px; text-indent: -999px; text-decoration: none; overflow: hidden; padding: 0px; margin: 0px;
  318.                background: transparent url(./images/advinvsys/send.png);
  319.            }
  320.            a.tooltip span {
  321.                display:none; padding:2px 3px; margin-left:-5px;
  322.            }
  323.            a.tooltip:hover span {
  324.                display:inline; position:absolute; border:1px solid #cccccc; background:#ffffff; color:#6c6c6c;
  325.            }
  326.        </style>
  327.        <link type="text/css" rel="stylesheet" href="./inc/plugins/advinvsys/jscripts/default.css" />
  328.        <script type="text/javascript" src="../jscripts/scriptaculous.js?load=effects"></script>
  329.        <script type="text/javascript" src="./inc/plugins/advinvsys/jscripts/window.js"> </script>
  330.        <script type="text/javascript" src="./inc/plugins/advinvsys/jscripts/window_effects.js"> </script>
  331.        <script type="text/javascript">
  332.            function previewEmail() {
  333.                 postData = "&message=" + encodeURIComponent(document.getElementById("message_new").value);
  334.                new Ajax.Request(\'xmlhttp.php?action=ais_previewEmail\', {
  335.                    method: \'post\',
  336.                    postBody: postData,
  337.                    onComplete: function(data) {
  338.                        text = data.responseText.replace(/(\r\n|\n|\r)/gm, "");
  339.                        if(text.match(/<success>(.*)<\/success>/)) {
  340.                            htmlb = text.match(/<success>(.*)<\/success>/);
  341.                            var win = new Window("previewEmail", {className: "dialog", width:350, height:200, zIndex: 100, resizable: true, title: "Preview Email Content", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, wiredDrag:true, destroyOnClose: true})
  342.                            win.setHTMLContent("<div align=\"left\">"+ htmlb[0] + "</div>");
  343.                            win.setStatusBar("<small>Copyright &copy; 2012 by <a href=\"http://mybb.ro\" target=\"_blank\">MyBB Romania</a>. All rights reserved.</small>");
  344.                            win.toFront();                            
  345.                            win.showCenter();
  346.                        }
  347.                    }
  348.                });
  349.            }
  350.        </script>'
  351.     );
  352.     $templates[] = array(
  353.         'title' => 'advinvsys_profile',
  354.         'template' => '<tr>
  355.            <td class="trow2"><strong>{$lang->advinvsys_profile_ins}:</strong></td>
  356.            <td class="trow2"><a href="{$mybb->settings[\'bburl\']}/usercp.php?action=advinvsys">{$invitations}</a>{$extra}{$extra1}</td>
  357.        </tr>'
  358.     );
  359.     $templates[] = array(
  360.         'title' => 'advinvsys_profile_extra',
  361.         'template' => '<span class="smalltext">[{$lang->advinvsys_profile_ref}: {$count}]</span>'
  362.     );
  363.     $templates[] = array(
  364.         'title' => 'advinvsys_profile_extra1',
  365.         'template' => '<span class="smalltext">[<a href="{$mybb->settings[\'bburl\']}/usercp.php?action=advinvsys&amp;method=send{$username}">{$lang->advinvsys_profile_send}</a>]</span>'
  366.     );
  367.     $templates[] = array(
  368.         "title" => "advinvsys_nav_option",
  369.         "template" => "<style>.usercp_nav_advinvsys {background: url(images/advinvsys/invitations.gif) no-repeat left center;}</style><tr><td class=\"trow1 smalltext\"><a href=\"{\$mybb->settings['bburl']}/{\$nav_link}\" class=\"{\$class1} {\$class2}\">{\$nav_text}</a></td></tr>"
  370.     );
  371.     $templates[] = array(
  372.         "title" => "advinvsys_registration_agreement",
  373.         "template" => '<input type="text" style="visibility: hidden;" value="{$value}" name="advinvsys_save_code" />'
  374.     );
  375.     $templates[] = array(
  376.         "title" => "advinvsys_registration_field",
  377.         "template" => "<br/>
  378. <fieldset class=\"trow2\">
  379. <legend><strong>{\$lang->advinvsys_reg_title}</strong></legend>
  380. <table cellspacing=\"0\" cellpadding=\"{\$theme['tablespace']}\">
  381. <tr>
  382. <td colspan=\"2\"><span class=\"smalltext\">{\$lang->advinvsys_reg_explain}</span></td>
  383. </tr>
  384. <tr>
  385. <td width=\"60%\"><br /><input type=\"text\" class=\"textbox\" name=\"advinvsys_reg_value\" value=\"{\$advinvsys_saved_code}\" id=\"advinvsys_reg_value\" style=\"width: 100%;\"/></td>
  386. <td align=\"right\" valign=\"bottom\"></td>
  387. </tr>
  388. <tr>
  389.     <td id=\"advinvsys_reg_status\"  style=\"display: none;\" colspan=\"2\">&nbsp;</td>
  390. </tr>
  391. </table>
  392. </fieldset>"
  393.     );
  394.     $templates[] = array(
  395.         'title' => 'advinvsys_send_form',
  396.         'template' => '<form action="usercp.php?action=advinvsys&amp;method=send" method="post">
  397.        {$errors}
  398.        <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  399.          <tbody>
  400.            <tr>
  401.              <td class="thead" colspan="2" width="100%">
  402.                <strong>{$lang->advinvsys_send_title}</strong>
  403.              </td>
  404.            </tr>
  405.            <tr>
  406.              <td class="trow1" width="50%">
  407.                  <strong>{$lang->advinvsys_send_user}</strong><br/>
  408.                  <span class="smalltext">{$lang->advinvsys_send_user_desc}</span>
  409.              </td>
  410.              <td class="trow1" width="50%">
  411.                  <input type="text" name="username" id="username" value="{$usr}" maxlength="32" />
  412.              </td>
  413.            </tr>
  414.            <tr>
  415.              <td class="trow2" width="50%">
  416.                  <strong>{$lang->advinvsys_send_amount}</strong><br/>
  417.                  <span class="smalltext">{$lang->advinvsys_send_amount_desc}</span>
  418.              </td>
  419.              <td class="trow2" width="50%">
  420.                  <input type="text" name="amount" id="amount" value="" /> ({$myinvitations})
  421.              </td>
  422.            </tr>
  423.            <tr>
  424.              <td class="trow1" width="50%">
  425.                  <strong>{$lang->advinvsys_send_reason}</strong><br/>
  426.                  <span class="smalltext">{$lang->advinvsys_send_reason_desc}</span>
  427.              </td>
  428.              <td class="trow1" width="50%">
  429.                  <textarea name="message" id="message"></textarea>
  430.              </td>
  431.            </tr>
  432.            <tr>
  433.              <td class="thead" colspan="2" align="center">
  434.                  <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
  435.                  <input type="submit" name="send_submit" value="{$lang->advinvsys_send_submit}" />
  436.                  <input type="reset" name="send_reset" value="{$lang->advinvsys_send_reset}" />
  437.              </td>
  438.            </tr>
  439.          </tbody>
  440.        </table>
  441. </form>'
  442.     );
  443.     $templates[] = array(
  444.         'title' => 'advinvsys_invite_form',
  445.         'template' => '<form action="usercp.php?action=advinvsys" method="post">
  446.        {$errors1}
  447.        <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  448.          <tbody>
  449.            <tr>
  450.              <td class="thead" colspan="2" width="100%">
  451.                <strong>{$lang->advinvsys_invite_title}</strong>
  452.              </td>
  453.            </tr>
  454.            <tr>
  455.              <td class="trow1" width="40%">
  456.                  <strong>{$lang->advinvsys_invite_email}</strong><br/>
  457.                  <span class="smalltext">{$lang->advinvsys_invite_email_desc}</span>
  458.              </td>
  459.              <td class="trow1" width="60%">
  460.                  <input type="text" name="email" id="email" value="" maxlength="64" />
  461.              </td>
  462.            </tr>
  463.            <tr>
  464.              <td class="trow1" width="40%">
  465.                  <strong>{$lang->advinvsys_invite_mess}</strong><br/>
  466.                  <span class="smalltext">{$lang->advinvsys_invite_mess_desc}</span>
  467.              </td>
  468.              <td class="trow1" width="60%">
  469.                  <textarea name="message" id="message" rows="8" cols="75" tabindex="2"></textarea>
  470.                  {$codebuttons}
  471.              </td>
  472.            </tr>
  473.            <tr>
  474.              <td class="thead" colspan="2" align="center">
  475.                  <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
  476.                  <input type="hidden" name="my_form" value="invite" />
  477.                  <input type="submit" name="send_submit" value="{$lang->advinvsys_invite_submit}" />        
  478.                  <input type="button" onclick="previewEmail()" value="{$lang->advinvsys_invite_preview}" />
  479.                  <input type="reset" name="send_reset" value="{$lang->advinvsys_send_reset}" />
  480.              </td>
  481.            </tr>
  482.          </tbody>
  483.        </table>
  484. </form>'
  485.     );
  486.     $templates[] = array(
  487.         'title' => 'advinvsys_buy_form',
  488.         'template' => '<form action="usercp.php?action=advinvsys" method="post">
  489.        {$errors2}
  490.        <table border="0" cellspacing="1" cellpadding="4" class="tborder">
  491.          <tbody>
  492.            <tr>
  493.              <td class="thead" colspan="2" width="100%">
  494.                <strong>{$lang->advinvsys_buy_title}</strong>
  495.              </td>
  496.            </tr>
  497.            <tr>
  498.              <td class="trow1" width="40%">
  499.                  <strong>{$lang->advinvsys_buy_gateway}</strong><br/>
  500.                  <span class="smalltext">{$lang->advinvsys_buy_gateway_desc}</span>
  501.              </td>
  502.              <td class="trow1" width="60%">
  503.                  <select name="gateway" id="gateway" size="1">
  504.                     {$options}
  505.                  </select>
  506.              </td>
  507.            </tr>
  508.            <tr>
  509.              <td class="trow2" width="40%">
  510.                  <strong>{$lang->advinvsys_buy_number}</strong><br/>
  511.                  <span class="smalltext">{$lang->advinvsys_buy_number_desc}</span>
  512.              </td>
  513.              <td class="trow2" width="60%" id="tdnumber">
  514.                  <select name="number" id="number" size="1">
  515.                     <option value="-">Chose one value  </option>
  516.                  </select>
  517.              </td>
  518.            </tr>
  519.            <tr>
  520.              <td class="trow1" width="40%">
  521.                  <strong>{$lang->advinvsys_buy_price}</strong><br/>
  522.                  <span class="smalltext">{$lang->advinvsys_buy_price_desc}</span>
  523.              </td>
  524.              <td class="trow1" width="60%">
  525.                  <input type="text" name="price" id="price" value="" readonly="readonly" style="text-align: right;" /><span id="currency"></span>
  526.              </td>
  527.            </tr>
  528.            <tr id="special_line">
  529.            </tr>
  530.            <tr>
  531.              <td class="thead" colspan="2" align="center">
  532.                  <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
  533.                  <input type="hidden" name="my_form" value="buy" />
  534.                  <input type="submit" name="buy_submit" id="buy_submit" value="{$lang->advinvsys_invite_submit}" />
  535.                  <input type="reset" name="buy_reset" value="{$lang->advinvsys_send_reset}" />
  536.              </td>
  537.            </tr>
  538.          </tbody>
  539.        </table>
  540. </form>'
  541.     );
  542.     $templates[] = array(
  543.         'title' => 'advinvsys_standard_page',
  544.         'template' => '<html><head>
  545.        <title>{$mybb->settings[bbname]} - {$title}</title>
  546.        {$headerinclude}{$extraheader}
  547.        </head><body>
  548.        {$header}
  549.        <table width="100%" border="0" align="center">
  550.        <tr>
  551.            {$usercpnav}
  552.            <td valign="top">
  553.                {$content}
  554.                <br/>
  555.                <div style="background: #efefef;border: 1px solid #4874a3;padding: 4px;"><div class="float_right" style="margin-top : -1px;"><img src="./images/advinvsys/version.png" alt="Version"/></div><span class="smalltext">Copyright &copy; 2012 by <a href="http://mybb.ro" target="_blank">MyBB Romania</a>. All rights reserved.</span></div>
  556.            </td>
  557.        </tr>
  558.        </table>
  559.        {$footer}
  560.        </body></html>'
  561.     );
  562.     $templates[] = array(
  563.         'title' => 'advinvsys_sms_buy',
  564.         'template' => '<table width="100%">
  565.        <tr>
  566.            <td width="40%"><b>{$lang->advinvsys_fortumo_show_key}</b> {$keyword} {$lang->advinvsys_fortumo_show_chs}</td>
  567.            <td width="30%"><b>{$lang->advinvsys_fortumo_show_code}</b> {$shortcode}</td>
  568.            <td width="30%"><b>{$lang->advinvsys_fortumo_show_ctr}</b> {$country}</td>
  569.        </tr>
  570.        <tr>
  571.            <td colspan="3"><div style="padding:0 10px 0 10px;margin-bottom:10px;border:#e5e4e2 solid 1px;background-color:#f6f8f7;width:100%px;overflow-x:auto">{$promotional}</div></td>
  572.        </tr></table>'
  573.     );
  574.    
  575.     // daca vectorul nu are elemente atunci se returneaza toate
  576.     if (count($ids) == 0)
  577.         return $templates;
  578.     else {
  579.         // se returneaza doar ce ne intereseaza
  580.         return array_intersect_key($templates, array_flip($ids));
  581.     }
  582. }
  583.  
  584. function advinvsys_get_settings($ids = array())
  585. {
  586.     $settings = array();
  587.     $settings[] = array(
  588.         "sid" => "NULL",
  589.         "name" => "setting_enable",
  590.         "title" => "[Core] Is this plugin enabled?",
  591.         "description" => "Can this plugin do his job? (Default : Yes)",
  592.         "optionscode" => "yesno",
  593.         "value" => "1"
  594.     );
  595.     $settings[] = array(
  596.         "sid" => "NULL",
  597.         "name" => "setting_only",
  598.         "title" => "[Core] Enable registration only with an invitation?",
  599.         "description" => "If it is set to \"No\", invites will not be checked on registration. But if it is set to \"Yes\" a invitation code will be required in order to register. (Default : Yes)",
  600.         "optionscode" => "yesno",
  601.         "value" => "1"
  602.     );
  603.     $settings[] = array(
  604.         "sid" => "NULL",
  605.         "name" => "setting_maxattempts",
  606.         "title" => "[Core] Set max attempts for registration :",
  607.         "description" => "After how many unsuccessful attempts to introduce a valid invitation code the registration process will be locked. Let empty or 0 to disable this feature. (Default : 5)",
  608.         "optionscode" => "text",
  609.         "value" => "5"
  610.     );
  611.     $settings[] = array(
  612.         "sid" => "NULL",
  613.         "name" => "setting_expattempts",
  614.         "title" => "[Core] Set time lock for unsuccessful attempts :",
  615.         "description" => "After how much time a user locked at registration process can try again? (Default : 10 Minutes)",
  616.         "optionscode" => "select\n10=10 Minutes\n30=30 Minutes\n60=1 Hour\n180=3 Hours",
  617.         "value" => "10"
  618.     );
  619.     $settings[] = array(
  620.         "sid" => "NULL",
  621.         "name" => "setting_showrefc",
  622.         "title" => "[Core] Display invited user count on his profile?",
  623.         'description' => "Do you want to display on user profile the number of people invited by him on this board? Default : Yes",
  624.         'optionscode' => "yesno",
  625.         'value' => "1"
  626.     );
  627.     $settings[] = array(
  628.         "sid" => "NULL",
  629.         "name" => "setting_sendemail",
  630.         "title" => "[Core] What message will be send when someone send an invitation?",
  631.         "description" => "Enter the message that you want to be send as email body, when someone generate and send an invitation using \"User CP\" section.",
  632.         "optionscode" => "textarea",
  633.         "value" => "Hello.\nThis message has been sent by a friend of yours known as <b>{INVITER_USERNAME}</b>, because he thinks that you may be interested in the following website: <a href=\"{BOARD_URL}\" target=\"_blank\">{BOARD_NAME}</a>.\n\nYou can use the following invitation code for registration : {INVITATION_CODE}\nHere you can register: <a href=\"{REGISTRATION_URL}\" target=\"_blank\">{REGISTRATION_URL}</a>\n\n<b><i>Your friend wrote:</i></b>\n-------------------------------------------\n{USER_MESSAGE}"
  634.     );
  635.     $settings[] = array(
  636.         "sid" => "NULL",
  637.         "name" => "setting_dateexpr",
  638.         "title" => "[Core] Expiration days :",
  639.         'description' => "After how many days an invitation already send will expire? (Default : 7)",
  640.         'optionscode' => "text",
  641.         'value' => "7"
  642.     );
  643.     $settings[] = array(
  644.         "sid" => "NULL",
  645.         "name" => "setting_giveexpr",
  646.         "title" => "[Core] Give credits for expired invitations?",
  647.         'description' => "Are you sure that you want to give back the credits taken for expired keys. (Default : Yes)",
  648.         'optionscode' => "yesno",
  649.         'value' => "1"
  650.     );
  651.     $settings[] = array(
  652.         "sid" => "NULL",
  653.         "name" => "setting_intresend",
  654.         "title" => "[Core] When a user can resend an email with an invitation?",
  655.         'description' => "After how many days an user can resend an invitation that was already sent in the past. (Default : 3)",
  656.         'optionscode' => "text",
  657.         'value' => "3"
  658.     );
  659.     $settings[] = array(
  660.         "sid" => "NULL",
  661.         "name" => "setting_timeonlinetype",
  662.         "title" => "[Income] Time spent online :",
  663.         'description' => "When the time spent online for a user increase with one value specified below then he will receive invitations according to the next setting. (Default : 12 Hours)",
  664.         'optionscode' => "select\n1=1 Hour\n6=6 Hours\n12=12 Hours\n24=1 Day\n72=3 Days\n168=7 Days",
  665.         'value' => "12"
  666.     );
  667.     $settings[] = array(
  668.         "sid" => "NULL",
  669.         "name" => "setting_timeonlinehow",
  670.         "title" => "[Income] How many invites will be given ?",
  671.         'description' => "How many invites will be given to user, according to the setting below this. Leave 0 if you want to disable this feature. (Default : 0)",
  672.         'optionscode' => "text",
  673.         'value' => "0"
  674.     );
  675.     $settings[] = array(
  676.         "sid" => "NULL",
  677.         "name" => "setting_paypalemail",
  678.         "title" => "[Paypal] Email address of PayPal account :",
  679.         "description" => "Please specify the email address for your <b>PayPal</b> account! This field it is required to enable <b>PayPal</b> gateway. (Default : )",
  680.         "optionscode" => "text",
  681.         "value" => ""
  682.     );
  683.     $settings[] = array(
  684.         "sid" => "NULL",
  685.         "name" => "setting_paypalcurr",
  686.         "title" => "[Paypal] Paypal currency :",
  687.         "description" => "What is the currency of this payment gateway? (Default : Euro)",
  688.         "optionscode" => "select\nEUR=Euro\nJPY=Japanese Yen\nGBP=Pound Sterling\nUSD=U.S. Dollar",
  689.         "value" => "EUR"
  690.     );
  691.     $settings[] = array(
  692.         "sid" => "NULL",
  693.         "name" => "setting_paypalcost",
  694.         "title" => "[Paypal] How much is an invitation?",
  695.         "description" => "How much is an invitation through <b>Paypal</b>. It will be used to calculate the final amount for a payment using <b>PayPal</b>! (Default : 1)",
  696.         "optionscode" => "text",
  697.         "value" => "1"
  698.     );
  699.     $settings[] = array(
  700.         "sid" => "NULL",
  701.         "name" => "setting_packages",
  702.         "title" => "[Paypal + NewPoints] Packages :",
  703.         "description" => "Packages of invitations that can be purchased via <b>PayPal</b> or <b>NewPoints</b>. You can use comma as separator. (Default : 1,5,10)",
  704.         "optionscode" => "text",
  705.         "value" => "1,5,10"
  706.     );
  707.     $settings[] = array(
  708.         "sid" => "NULL",
  709.         "name" => "setting_newpointsenable",
  710.         "title" => "[NewPoints] Is this gateway enabled? :",
  711.         "description" => "Can a user buy invitations using <b>NewPoints</b> plugin? (Default : No)",
  712.         "optionscode" => "yesno",
  713.         "value" => "0"
  714.     );
  715.     $settings[] = array(
  716.         "sid" => "NULL",
  717.         "name" => "setting_newpointscost",
  718.         "title" => "[NewPoints] How much is an invitation?",
  719.         "description" => "How much is an invitation through <b>NewPoints</b>. It will be used to calculate the final amount for a payment using NewPoints! (Default : 10)",
  720.         "optionscode" => "text",
  721.         "value" => "10"
  722.     );
  723.     $settings[] = array(
  724.         "sid" => "NULL",
  725.         "name" => "setting_smsenable",
  726.         "title" => "[SMS] Is this gateway enabled?",
  727.         "description" => "Can a user buy invitations using SMS gateway? (Default : No)",
  728.         "optionscode" => "yesno",
  729.         "value" => "0"
  730.     );
  731.     $settings[] = array(
  732.         "sid" => "NULL",
  733.         "name" => "setting_smsid",
  734.         "title" => "[SMS] Service ID :",
  735.         "description" => "Insert your service ID below, in order to make SMS-Fortumo gateway to work fine. The field it is required to enable this payment gateway! (Default : )",
  736.         "optionscode" => "text",
  737.         "value" => ""
  738.     );
  739.     $settings[] = array(
  740.         "sid" => "NULL",
  741.         "name" => "setting_smssecret",
  742.         "title" => "[SMS] Secret Code :",
  743.         "description" => "You need to add in this textfield a secret code from Fortumo. Also this field it is required in order to activate SMS payment gateway! (Default : )",
  744.         "optionscode" => "text",
  745.         "value" => ""
  746.     );
  747.     $settings[] = array(
  748.         "sid" => "NULL",
  749.         "name" => "setting_smssig",
  750.         "title" => "[SMS] Signature :",
  751.         "description" => "The signature has 32 carachters and can be found on <i>Fortumo > Dashboard > My services > Setup</i> page. A user cannot buy using this gateway until you do not type a value on this field. (Default : )",
  752.         "optionscode" => "text",
  753.         "value" => ""
  754.     );
  755.     $settings[] = array(
  756.         "sid" => "NULL",
  757.         "name" => "setting_smsinvs",
  758.         "title" => "[SMS] Amount of invitations",
  759.         "description" => "Set amount of invitations that can be purchased using <b>SMS - Fortumo</b>. (Default : 1)",
  760.         "optionscode" => "text",
  761.         "value" => "1"
  762.     );
  763.     $settings[] = array(
  764.         "sid" => "NULL",
  765.         "name" => "setting_smssendpm",
  766.         "title" => "[PM] Send PM to buyer?",
  767.         "description" => "If it is set to \"Yes\" then when a user buy some invitations using a gateway, the system will send a PM to him. (Default : Yes)",
  768.         "optionscode" => "yesno",
  769.         "value" => "1"
  770.     );
  771.     $settings[] = array(
  772.         "sid" => "NULL",
  773.         "name" => "setting_smssendpmm",
  774.         "title" => "[PM] What message will be sent ?",
  775.         "description" => "If setting \"Send PM to buyer?\" is set to \"Yes\" then here you can specify a custom message that will be send as PM.",
  776.         "optionscode" => "textarea",
  777.         "value" => "Hi {USER_NAME}! ({USER_EMAIL})!\n Thank you for items purchased!"
  778.     );
  779.     $settings[] = array(
  780.         "sid" => "NULL",
  781.         "name" => "setting_smssendemail",
  782.         "title" => "[Email] What message will be sent ?",
  783.         "description" => "What message will be sent as email when someone buys an invitation using PayPal or SMS - Fortumo?",
  784.         "optionscode" => "textarea",
  785.         "value" => "Hi.\nThis message contains an invitation code that you have bought using {GATEWAY} in order to register on our board - <a href=\"{BOARD_URL}\" target=\"_blank\">{BOARD_NAME}</a>.\n\nYour invitation code is {INVITATION_CODE}.\nHere you can register: <a href=\"{REGISTRATION_URL}\" target=\"_blank\">{REGISTRATION_URL}</a>\n\nThank you for purchasing this invitation."
  786.     );
  787.    
  788.     // daca vectorul nu are elemente atunci se returneaza toate
  789.     if (count($ids) == 0)
  790.         return $settings;
  791.     else {
  792.         // se returneaza doar ce ne intereseaza
  793.         return array_intersect_key($settings, array_flip($ids));
  794.     }
  795. }
  796.  
  797. // Se incarca modificarile in panoul de administrare
  798. function advinvsys_admin_load_hook() {
  799.     global $cache, $plugins, $mybb, $theme, $db, $templates;
  800.  
  801.     advinvsys_load_modules();
  802. }
  803.  
  804. // Se incarca modificarile pentru interfata cu utilizatorul
  805. function advinvsys_plugins_start() {
  806.     global $cache, $plugins, $mybb, $theme, $db, $templates;
  807.  
  808.     advinvsys_load_modules();
  809. }
  810.  
  811. // Functia adauga informatie in cadrul paginii de statistici
  812. function advinvsys_stats() {
  813.     global $db, $lang, $stats, $advinvsys_invsperusers, $AISDevelop;
  814.    
  815.     // se incarca fisierul de limba
  816.     $lang->load('advinvsys');
  817.    
  818.     // se seteaza numarul total de invitatii
  819.     $query = $db->simple_select('users', 'SUM(invitations) AS total', '');
  820.     $stats['totalinvs'] = floatval($db->fetch_field($query, 'total'));
  821.    
  822.     // variabila retine numarul de invitatii per membru!
  823.     if ((int)$stats['numusers'] != 0) {
  824.         $advinvsys_invsperusers = $AISDevelop->truncNumber($stats['totalinvs'] / $stats['numusers']);
  825.     } else {
  826.         $advinvsys_invsperusers = 'NaN';
  827.     }
  828. }
  829.  
  830. // Functia afiseaza o serie de informatii in profilul utilizatorului
  831. function advinvsys_profile() {
  832.     global $mybb, $db, $templates, $memprofile, $advinvsys_profile, $lang, $plugins, $AISDevelop;
  833.  
  834.     // verificam daca este activa aceasta functie
  835.     if ($mybb->settings['advinvsys_setting_enable'] != 1) {
  836.         $advinvsys_profile = '';
  837.         return;
  838.     }
  839.  
  840.     // se permite adaugarea unor alte portiuni de coduri
  841.     $plugins->run_hooks('advinvsys_profile_start');
  842.  
  843.     // daca e activa atunci se afiseaza
  844.     $lang->load('advinvsys');
  845.  
  846.     // cate invitatii are persoana de fata?
  847.     $invitations = $AISDevelop->truncNumber($memprofile['invitations']);
  848.  
  849.     // informatii aditionale
  850.     $extra = '';
  851.     $extra1 = '';
  852.     if ($mybb->settings['advinvsys_setting_showrefc'] == 1) {
  853.  
  854.         // care este uid-ul ei
  855.         $uid = intval($memprofile['uid']);
  856.  
  857.         // se intoarce din baza de date numarul de persoane aduse pe forum
  858.         $query = $db->write_query("SELECT COUNT(uid) AS number FROM " . TABLE_PREFIX . "users
  859.                WHERE invitation_refer = '{$uid}'");
  860.  
  861.         if ($row = $db->fetch_array($query)) {
  862.             $count = intval($row['number']);
  863.             eval("\$extra .= \"" . $templates->get('advinvsys_profile_extra') . "\";");
  864.         }
  865.     }
  866.  
  867.     // nu iti poti trimite singur invitatii
  868.     // nici un vizitator nu iti poate trimite invitatii
  869.     if ($mybb->user['uid'] && $memprofile['uid'] != $mybb->user['uid']) {
  870.         $username = '&amp;usrn=' . $memprofile['username'];
  871.         eval("\$extra1 .= \"" . $templates->get('advinvsys_profile_extra1') . "\";");
  872.     }
  873.  
  874.     // se permite adaugarea unor alte portiuni de coduri
  875.     $plugins->run_hooks('advinvsys_profile_end');
  876.  
  877.     // se afiseaza in profil informatiile legate de sistemul de invitatii
  878.     eval("\$advinvsys_profile = \"" . $templates->get('advinvsys_profile') . "\";");
  879. }
  880.  
  881. // Functria este folosita pentru verificarea unei invitatii
  882. function advinvsys_user_validate($data) {
  883.     global $mybb, $db, $lang, $plugins;
  884.  
  885.     // ne intereseaza sa realizam testele doar daca vizitatorul doreste sa se
  886.     // inregistreze si acest plugin este activat
  887.     if ($mybb->settings['advinvsys_setting_enable'] == 1 &&
  888.             $mybb->settings['advinvsys_setting_only'] == 1 &&
  889.             $mybb->input['action'] == 'do_register') {
  890.  
  891.         // se incarca fisierul lingvistic
  892.         $lang->load("advinvsys");
  893.  
  894.         // se pornesc sesiunile
  895.         session_start();
  896.  
  897.         // verificam daca nu cumva a depasit numarul de incercari
  898.         $maxattempts = intval($mybb->settings['advinvsys_setting_maxattempts']);
  899.         if (isset($_SESSION['advinvsys_maxattemps']['attemps']) && $maxattempts > 0 &&
  900.                 $_SESSION['advinvsys_maxattemps']['attemps'] >= $maxattempts) {
  901.             $maxtime = intval($mybb->settings['advinvsys_setting_expattempts']);
  902.             // ne asiguram ca nu se poate cobora sub 10 minute
  903.             if ($maxtime < 10)
  904.                 $maxtime = 10;
  905.  
  906.             // daca timpul sesiunii a expirat atunci se sterge sesiunea
  907.             if (isset($_SESSION['advinvsys_maxattemps']['timestamp']) &&
  908.                     $_SESSION['advinvsys_maxattemps']['timestamp'] <
  909.                     intval(TIME_NOW - $maxtime * 60)) {
  910.  
  911.                 // acum ar trebui sa se poata inregistra
  912.                 unset($_SESSION['advinvsys_maxattemps']);
  913.             } else {
  914.                 // altfel inseamna ca avem o eroare
  915.                 $data->set_error($lang->sprintf($lang->advinvsys_reg_maxattempts, $maxtime));
  916.  
  917.                 // se iese imediat
  918.                 return;
  919.             }
  920.         }
  921.  
  922.         // se verifica daca codul introdus exista in baza de date
  923.         $inv_code = $db->escape_string($mybb->input['advinvsys_reg_value']);
  924.  
  925.         // si daca invitatia nu a expirat
  926.         $days_expr = (is_numeric($mybb->settings['advinvsys_setting_dateexpr']))
  927.             ? abs($mybb->settings['advinvsys_setting_dateexpr'])
  928.             : 7; // 7 zile in mod implicit
  929.         // interogarea
  930.         $query = $db->simple_select('advinvsys_codes', '*', "code = '{$inv_code}'
  931.            AND date > " . intval(TIME_NOW - intval($days_expr) * 86400), array('limit' => 1));
  932.  
  933.         if (!($row = $db->fetch_array($query))) {
  934.             // doar in cazul in care invitatia nu exista in sistem se seteaza o eroare
  935.             $data->set_error($lang->advinvsys_reg_wrong_answer);
  936.  
  937.             // inainte de a se iesi din functie se incrementeaza contorul de autentificari esuate
  938.             if (!isset($_SESSION['advinvsys_maxattemps'])) {
  939.                 // o vom seta pe 1
  940.                 $_SESSION['advinvsys_maxattemps'] = array(
  941.                     'attemps' => 1,
  942.                     'timestamp' => TIME_NOW
  943.                 );
  944.             } else {
  945.                 $array = $_SESSION['advinvsys_maxattemps'];
  946.                 // se fac reactualizarile
  947.                 $_SESSION['advinvsys_maxattemps'] = array(
  948.                     'attemps' => $array['attemps'] + 1,
  949.                     'timestamp' => TIME_NOW
  950.                 );
  951.             }
  952.  
  953.             // se iese imediat
  954.             return;
  955.         }
  956.  
  957.         // se permite adaugarea unor alte portiuni de coduri
  958.         $data = $plugins->run_hooks('advinvsys_user_do_validate', $data);
  959.         // pe cealalta ramura nu se face nimic
  960.     }
  961.     // se returneaza informatiile primite si prelucrate
  962.     return $data;
  963. }
  964.  
  965. // Functia este apelata imediat dupa inregistrarea utilizatorului
  966. function advinvsys_do_register() {
  967.     global $mybb, $db, $user, $user_info, $plugins;
  968.  
  969.     // ne intereseaza sa realizam testele doar daca vizitatorul doreste sa se
  970.     // inregistreze si acest plugin este activat
  971.     if ($mybb->settings['advinvsys_setting_enable'] == 1 &&
  972.             $mybb->input['action'] == "do_register") {
  973.         $inv_code = $db->escape_string($mybb->input['advinvsys_reg_value']);
  974.  
  975.         // cine a invitat aceasta persoana ?
  976.         $db->write_query('UPDATE ' . TABLE_PREFIX . 'users u, (SELECT did AS user_id
  977.            FROM ' . TABLE_PREFIX . 'advinvsys_codes WHERE code = \'' . $inv_code . '\'
  978.            LIMIT 1) AS u1 SET u.invitation_refer = GREATEST(0, u1.user_id)
  979.            WHERE u.uid = \'' . $user_info['uid'] . '\'');
  980.  
  981.         // se permite adaugarea unor alte portiuni de coduri
  982.         $plugins->run_hooks('advinvsys_member_do_register');
  983.  
  984.         // daca e sistemul atunci se lasa pe 0
  985.         // invitatia se sterge din baza de date
  986.         $db->delete_query('advinvsys_codes', "code = '{$inv_code}'");
  987.  
  988.         // de asemenea se proceseaza si invitatiile expirate (daca sunt!)
  989.     }
  990.     return $data;
  991. }
  992.  
  993. // Functia care permite inregistrarea utilizand un cod de invitatie primit prin e-mail
  994. function advinvsys_register_agreement() {
  995.     global $mybb, $db, $advinvsys_save_code, $templates;
  996.  
  997.     // este modificarea activa?
  998.     if ($mybb->settings['advinvsys_setting_enable'] == 1) {
  999.         $value = "";
  1000.        
  1001.         // exista un cod setat pentru modificare?
  1002.         if (isset($mybb->input['code']) && strlen($mybb->input['code']) == 32)
  1003.             $value = $db->escape_string($mybb->input['code']);
  1004.        
  1005.         eval("\$advinvsys_save_code .= \"" .
  1006.                 $templates->get('advinvsys_registration_agreement') . "\";");    
  1007.     }
  1008. }
  1009.  
  1010. // Functia care afiseaza pe ecran campul "Invitation Code" din cadrul formularului de inregistrare
  1011. function advinvsys_register_end() {
  1012.     global $mybb, $db, $templates, $theme, $lang, $advinvsys_reg_field, $validator_extra;
  1013.  
  1014.     if ($mybb->settings['advinvsys_setting_enable'] == 1) {
  1015.  
  1016.         // se incarca fisierul lingvistic al aplicatiei
  1017.         $lang->load('advinvsys');
  1018.  
  1019.         // in mod normal este afisat campul
  1020.         $advinvsys_saved_code = "";
  1021.  
  1022.         // se verifica daca codul de inregistrare are 32 de caractere
  1023.         if (isset($mybb->input['advinvsys_save_code']) && strlen($mybb->input['advinvsys_save_code']) == 32) {
  1024.             $advinvsys_saved_code = $db->escape_string($mybb->input['advinvsys_save_code']);
  1025.         }
  1026.  
  1027.         // se adauga un extra validator
  1028.         $validator_extra .= "\tregValidator.register('advinvsys_reg_value', 'ajax', {url:'xmlhttp.php?action=advinvsys_validate', loading_message:'{$lang->regq_checking}', failure_message:'{$lang->regq_wrong_answer}'});\n";
  1029.  
  1030.         eval("\$advinvsys_reg_field = \"" . $templates->get("advinvsys_registration_field") . "\";");
  1031.     } else {
  1032.         eval("\$advinvsys_reg_field = \"\";");
  1033.     }
  1034. }
  1035.  
  1036. // Functia care valideaza un cod de invitatie
  1037. function advinvsys_xmlhttp() {
  1038.     global $mybb, $db, $lang, $charset, $AISDevelop;
  1039.  
  1040.     // se include fisierul de limba
  1041.     $lang->load("advinvsys");
  1042.  
  1043.     // daca actiunea curenta este cea de validare a unui cod de invitatie
  1044.     if ($mybb->input['action'] == 'advinvsys_validate') {
  1045.  
  1046.         // se schimba antetul modificarii
  1047.         header("Content-type: text/xml; charset={$charset}");
  1048.         $inv_code = $db->escape_string($mybb->input['value']);
  1049.  
  1050.         // se verifica daca codul exista in baza de date
  1051.         $query = $db->simple_select('advinvsys_codes', '*',
  1052.                 "code = '{$inv_code}'", array('limit' => 1));
  1053.  
  1054.         if (!($row = $db->fetch_array($query))) {
  1055.             // codul invitatiei nu exista in baza de date
  1056.             echo "<fail>{$lang->advinvsys_reg_wrong_answer}</fail>";
  1057.         } else {
  1058.             // codul invitatiei exista si poate fi folosit
  1059.             echo "<success>{$lang->advinvsys_reg_correct_answer}</success>";
  1060.         }
  1061.  
  1062.         // se iese fortat
  1063.         exit;
  1064.     } else if ($mybb->input['action'] == 'ais_previewEmail') {
  1065.         // se parseaza bbcode-urile
  1066.         if (!class_exists('postParser'))
  1067.             require_once MYBB_ROOT . 'inc/class_parser.php';
  1068.  
  1069.         $parser1 = new postParser;
  1070.  
  1071.         $body = nl2br($mybb->settings['advinvsys_setting_sendemail']);
  1072.  
  1073.         $message = $mybb->input['message'];
  1074.         $message = $parser1->parse_message($message, array(
  1075.             'allow_html' => 0,
  1076.             'allow_smilies' => 0,
  1077.             'allow_mycode' => 1,
  1078.             'filter_badwords' => 1
  1079.                 ));
  1080.  
  1081.         echo "<success>" . $AISDevelop->parseBody($body,
  1082.                 md5('PREVIEW_MODE'), $message) . "</success>";
  1083.         exit;
  1084.     } else if ($mybb->input['action'] == 'ais_smsfortumo') {
  1085.         try {
  1086.  
  1087.             $result = advinvsys_get_sms_data(
  1088.                     'http://api.fortumo.com/api/services/2/' . $mybb->settings['advinvsys_setting_smsid'] .
  1089.                     '.' . $mybb->settings['advinvsys_setting_smssig'] . '.xml',
  1090.                     advinvsys_country_recognition($_SERVER['REMOTE_ADDR']),
  1091.                     $lang->advinvsys_fortumo_buy_err3,
  1092.                     $lang->advinvsys_fortumo_buy_err2
  1093.             );
  1094.  
  1095.             echo "<success>{$result}</success>";
  1096.         } catch (Exception $ex) {
  1097.  
  1098.             echo "<fail>{$lang->advinvsys_fortumo_buy_err1}</fail>";
  1099.         }
  1100.     }
  1101. }
  1102.  
  1103. // Functia care adauga in cadrul meniului din User CP un link catre formularul
  1104. // de trimitere a unei invitatii
  1105. function advinvsys_menu_built() {
  1106.     global $mybb;
  1107.  
  1108.     // daca modificarea nu este activa atunci legatura nu va aparea in meniu
  1109.     if ($mybb->settings['advinvsys_setting_enable'] != 1) {
  1110.         return;
  1111.     }
  1112.  
  1113.     // altfel va aparea
  1114.     global $lang, $templates, $usercpmenu;
  1115.  
  1116.     // se incarca fisierul de limba al modificarii
  1117.     $lang->load('advinvsys');
  1118.  
  1119.     // daca ne aflam in scriptul usercp.php sau private.php?
  1120.     if (in_array(THIS_SCRIPT, array('private.php', 'usercp.php'))) {
  1121.  
  1122.         $advinvsys_nav_option = "";
  1123.         $class1 = "usercp_nav_item";
  1124.         $class2 = "usercp_nav_advinvsys";
  1125.         $nav_link = "usercp.php?action=advinvsys";
  1126.         $nav_text = $lang->advinvsys_usercp_my;
  1127.  
  1128.         // adauga codul optiunii tale
  1129.         eval("\$usercpmenu .= \"" . $templates->get("advinvsys_nav_option") . "\";");
  1130.     }
  1131. }
  1132.  
  1133. // CEA MAI IMPORTANTA FUNCTIE!
  1134. // Functia ce afiseaza pe ecran formularul de trimitere a unei invitatii
  1135. function advinvsys_main_page() {
  1136.     global $mybb;
  1137.  
  1138.     // este activa modificarea?
  1139.     if ($mybb->settings['advinvsys_setting_enable'] != 1) {
  1140.         return;
  1141.     }
  1142.  
  1143.     // daca este activa se afiseaza pagina pe ecran
  1144.     global $db, $cache, $plugins, $config, $lang, $theme, $templates, $forum,
  1145.             $headerinclude, $header, $footer, $usercpnav, $AISDevelop;
  1146.  
  1147.     // mai intai se incarca fisierul de limba
  1148.     $lang->load('advinvsys');
  1149.  
  1150.     // alte teste
  1151.     if (THIS_SCRIPT != 'usercp.php' || $mybb->input['action'] != 'advinvsys')
  1152.         return;
  1153.  
  1154.     // se include clasa necesara tabelelor
  1155.     if (!class_exists('DefaultTable'))
  1156.         require_once MYBB_ROOT . '/inc/plugins/advinvsys/classes/class_table.php';
  1157.     // se vor parsa mesajele optionale
  1158.     if (!class_exists('postParser'))
  1159.         require_once MYBB_ROOT . 'inc/class_parser.php';
  1160.     $parser = new postParser;
  1161.  
  1162.     $extraheader = '';
  1163.     $content = '';
  1164.  
  1165.     $plugins->run_hooks('advinvsys_mainpage_start');
  1166.  
  1167.     if ($mybb->input['method'] == 'send') {
  1168.         if ($mybb->request_method == "post") {
  1169.             if (!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key']) {
  1170.                 $mybb->request_method = "get";
  1171.                 $errors[] = $lang->advinvsys_errors_invalidreq;
  1172.             }
  1173.  
  1174.             $amount = floatval($mybb->input['amount']);
  1175.             $username = $db->escape_string($mybb->input['username']);
  1176.  
  1177.             $plugins->run_hooks('advinvsys_mainpage_do_donate_start');
  1178.  
  1179.             // se verifica daca nu cumva isi doneaza tot lui
  1180.             if ($username == $mybb->user['username']) {
  1181.                 // iar vom genera o eroare
  1182.                 $errors[] = $lang->advinvsys_send_selfdonate;
  1183.             }
  1184.  
  1185.             // valoarea introdusa e buna?
  1186.             if (!is_numeric($amount) || strlen($amount) > 12 || $amount <= 0) {
  1187.                 // o noua eroare
  1188.                 $errors[] = $lang->advinvsys_send_erramount;
  1189.             }
  1190.  
  1191.             // exista utilizatorul (+ sa fie unic)
  1192.             if (!($uid = $db->fetch_field($db->simple_select('users', '*',
  1193.                     'username = \'' . $username . '\''), 'uid'))) {
  1194.                 $errors[] = $lang->advinvsys_send_erruser;
  1195.             }
  1196.  
  1197.             // se verifica daca se pot lua invitatiile de la cel care doneaza... are destule?
  1198.             $invs = $AISDevelop->checkInvitations('uid', $mybb->user['uid'], $amount);
  1199.             if ($invs == false) {
  1200.                 // donatorul nu are suficiente invitatii
  1201.                 // apare eroare
  1202.                 $errors[] = $lang->sprintf($lang->advinvsys_send_notenough,
  1203.                         $mybb->user['invitations']);
  1204.             }
  1205.  
  1206.             // au aparut erori?
  1207.             if (count($errors) == 0) {
  1208.  
  1209.                 // se poate face transferul
  1210.                 // se adauga utilizatorului invitatiile
  1211.                 $AISDevelop->addInvitations('username', $username, $amount, false, false);
  1212.  
  1213.                 // se scad donatorului invitatiile
  1214.                 $AISDevelop->addInvitations('uid', $mybb->user['uid'], -$amount, false, false);
  1215.  
  1216.                 // mai trebuie sa introducem un log in baza de date
  1217.                 $AISDevelop->addLog($lang->advinvsys_send_log_type,
  1218.                     $lang->sprintf($lang->advinvsys_send_log, $amount, $username),
  1219.                     $mybb->user['uid']);
  1220.  
  1221.                 // de asemenea se va trimite si un PM
  1222.                 if ($mybb->input['message'] != '') {
  1223.                     $AISDevelop->sendPM(array(
  1224.                         'subject' => $lang->advinvsys_send_pmsubject,
  1225.                         'message' => $lang->sprintf($lang->advinvsys_send_pmmessage_reason,
  1226.                                 $amount, htmlspecialchars_uni($mybb->input['message'])),
  1227.                         'receivepms' => 1,
  1228.                         'touid' => $uid
  1229.                     ));
  1230.                 } else {
  1231.                     $AISDevelop->sendPM(array(
  1232.                         'subject' => $lang->advinvsys_send_pmsubject,
  1233.                         'message' => $lang->sprintf($lang->advinvsys_send_pmmessage, $amount),
  1234.                         'receivepms' => 1,
  1235.                         'touid' => $uid
  1236.                     ));
  1237.                 }
  1238.  
  1239.                 $plugins->run_hooks('advinvsys_mainpage_do_donate_end');
  1240.  
  1241.                 // se face redirectionarea
  1242.                 redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1243.                         $lang->sprintf($lang->advinvsys_send_donated, $amount, intval($invs - $amount)));
  1244.             } else {
  1245.                 // se afiseaza erorile frumos pe ecran
  1246.                 $errors = inline_error($errors);
  1247.             }
  1248.         }
  1249.        
  1250.         eval("\$extraheader = \"" . $templates->get("advinvsys_donate_header") . "\";");
  1251.  
  1252.         $usr = htmlspecialchars_uni($mybb->input['usrn']);
  1253.         $myinvitations = $lang->sprintf($lang->advinvsys_send_amount_have,
  1254.                 $mybb->user['invitations']);
  1255.  
  1256.         $plugins->run_hooks('advinvsys_mainpage_donate');
  1257.  
  1258.         eval("\$form = \"" . $templates->get("advinvsys_send_form") . "\";");
  1259.         $content .= $form;
  1260.     } else {
  1261.         if (isset($mybb->input['send_submit']) && $mybb->request_method == 'post'
  1262.                 && $mybb->input['my_form'] == 'invite') {
  1263.             // se verifica autenticitatea cererii
  1264.             if (!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key']) {
  1265.                 $mybb->request_method = "get";
  1266.                 $errors1[] = $lang->advinvsys_errors_invalidreq;
  1267.             }
  1268.  
  1269.             $email = $db->escape_string($mybb->input['email']);
  1270.             $message = $db->escape_string($mybb->input['message']);
  1271.  
  1272.             $plugins->run_hooks('advinvsys_mainpage_do_invite_start');
  1273.  
  1274.             // se verifica faptul ca adresa de e-mail introdusa este una valida
  1275.             if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  1276.                 // se va genera o eroare
  1277.                 $errors1[] = $lang->advinvsys_invite_invalidemail;
  1278.             }
  1279.  
  1280.             // se verifica daca nu cumva isi acorda o invitatie tot lui
  1281.             if (strcmp($email, $mybb->user['email']) == 0) {
  1282.                 // iar vom genera o eroare
  1283.                 $errors1[] = $lang->advinvsys_invite_selfinvite;
  1284.             }
  1285.  
  1286.             // verificam daca nu cumva aceeasi adresa de email a fost invitata deja
  1287.             if (!empty($email) && $AISDevelop->checkInvitationSent('email', $email)) {
  1288.                 // va aparea un nou mesaj
  1289.                 $errors1[] = $lang->advinvsys_invite_multiple;
  1290.             }
  1291.  
  1292.             // se verifica daca se poate lua o invitatie de la cel care invita...
  1293.             $invs = $AISDevelop->checkInvitations('uid', $mybb->user['uid'], 1);
  1294.             if ($invs == false) {
  1295.                 // donatorul nu are suficiente invitatii
  1296.                 // apare eroare
  1297.                 $errors1[] = $lang->sprintf($lang->advinvsys_send_notenough, $mybb->user['invitations']);
  1298.             }
  1299.  
  1300.             // se poate trimite invitatia?
  1301.             if (count($errors1) == 0) {
  1302.                 // se scade celui care a invitat o invitatie
  1303.                 $AISDevelop->addInvitations('uid', $mybb->user['uid'], -1, false, false);
  1304.  
  1305.                 // mai trebuie sa introducem un log in baza de date
  1306.                 $AISDevelop->addLog($lang->advinvsys_invite_log_type,
  1307.                     $lang->sprintf($lang->advinvsys_invite_log, $email),
  1308.                     $mybb->user['uid']);
  1309.  
  1310.                 // de asemenea se va trimite si un email]
  1311.                 $body = nl2br($mybb->settings['advinvsys_setting_sendemail']);
  1312.                 $message = $parser->parse_message($message, array(
  1313.                     'allow_html' => 0,
  1314.                     'allow_smilies' => 0,
  1315.                     'allow_mycode' => 1,
  1316.                     'filter_badwords' => 1
  1317.                         ));
  1318.                
  1319.                 $key = $AISDevelop->generateInvitation($mybb->user['uid'], $email, true);
  1320.                 if (!empty($email))
  1321.                     my_mail($email, 'Invitation', $AISDevelop->parseBody($body, $key, $message),
  1322.                         '', '', '', false, 'html');
  1323.  
  1324.                 $plugins->run_hooks('advinvsys_mainpage_do_invite_end');
  1325.  
  1326.                 // se face redirectionarea
  1327.                 redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1328.                         $lang->sprintf($lang->advinvsys_invite_gived, 1, intval($invs - 1)));
  1329.             } else {
  1330.                 // se afiseaza erorile frumos pe ecran
  1331.                 $errors1 = inline_error($errors1);
  1332.             }
  1333.         } else if (isset($mybb->input['buy_submit']) && $mybb->request_method == 'post'
  1334.                 && $mybb->input['my_form'] == 'buy') {
  1335.             // se verifica autenticitatea cererii
  1336.             if (!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key']) {
  1337.                 $mybb->request_method = "get";
  1338.                 $errors2[] = $lang->advinvsys_errors_invalidreq;
  1339.             }
  1340.  
  1341.             $amount = floatval($mybb->input['price']);
  1342.             $number = floatval($mybb->input['number']);
  1343.             $gateway = $db->escape_string($mybb->input['gateway']);
  1344.             $avaible = array(
  1345.                 'newpoints'
  1346.             );
  1347.  
  1348.             $plugins->run_hooks('advinvsys_mainpage_do_buy_start');
  1349.  
  1350.             if (!in_array($gateway, $avaible)) {
  1351.                 // se va genera o eroare
  1352.                 $errors2[] = $lang->advinvsys_buy_invalidgateway;
  1353.             }
  1354.  
  1355.             if ($amount <= 0) {
  1356.                 // eroare si de aceasta data
  1357.                 $errors2[] = $lang->advinvsys_buy_invalidprice;
  1358.             }
  1359.  
  1360.             // verificam daca se poate lua suma necesara
  1361.             $check = advinvsys_check_convert($mybb->user['uid'], $amount, $gateway);
  1362.             if (!$check) {
  1363.                 // eroare
  1364.                 $errors2[] = $lang->advinvsys_buy_notenough;
  1365.             }
  1366.  
  1367.             // se poate procesa cererea?
  1368.             if (count($errors2) == 0) {
  1369.                 // se iau punctele utilizatorului
  1370.                 advinvsys_take_convert($mybb->user['uid'], $amount, $gateway);
  1371.  
  1372.                 // se acorda numarul de invitatii specificat
  1373.                 $AISDevelop->addInvitations('uid', $mybb->user['uid'], $number, false, false);
  1374.  
  1375.                 // se adauga si un jurnal in sistem
  1376.                 $AISDevelop->addLog($lang->advinvsys_buy_np_logt,
  1377.                     $lang->sprintf($lang->advinvsys_buy_np_log, $amount,
  1378.                         $AISDevelop->truncNumber($number)),
  1379.                     $mybb->user['uid']);
  1380.  
  1381.                 // un simplu carlig
  1382.                 $plugins->run_hooks('advinvsys_mainpage_do_buy_end');
  1383.  
  1384.                 // se realizeaza o redirectionare
  1385.                 redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1386.                         $lang->sprintf($lang->advinvsys_buy_succes, $number,
  1387.                                 $AISDevelop->truncNumber($mybb->user['invitations'] + $number)));
  1388.             } else {
  1389.                 // se afiseaza erorile frumos pe ecran
  1390.                 $errors2 = inline_error($errors2);
  1391.             }
  1392.         } else if (isset($mybb->input['type'])
  1393.                 && $mybb->input['type'] == 'resend') {
  1394.             // se verifica autenticitatea cererii
  1395.             if (!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key']) {
  1396.                 $errors0[] = $lang->advinvsys_errors_invalidreq;
  1397.             }
  1398.  
  1399.             $cid = intval($mybb->input['id']);
  1400.  
  1401.             $plugins->run_hooks('advinvsys_mainpage_do_resend_start');
  1402.  
  1403.             $interval = (is_numeric($mybb->settings['advinvsys_setting_intresend'])) ?
  1404.                 abs($mybb->settings['advinvsys_setting_intresend']) : 3;
  1405.             $query = $db->simple_select('advinvsys_codes', '*', 'date < ' .
  1406.                     intval(TIME_NOW - $interval * 86400) .
  1407.                     ' AND cid = ' . intval($cid));
  1408.            
  1409.             if ($db->num_rows($query) == 0) {
  1410.                 // invitatia nu exista in sistem sau nu poti retrimite invitatia
  1411.                 $errors0[] = $lang->advinvsys_resend_err1;
  1412.             } else {
  1413.                 $row = $db->fetch_array($query);
  1414.                
  1415.                 // verificam daca invitatia apartine utilizatorului curent
  1416.                 if (intval($row['did']) != $mybb->user['uid'])
  1417.                     $errors0[] = $lang->advinvsys_giveback_err2;
  1418.                    
  1419.                 // verificam daca are atasata o adresa de email
  1420.                 if (empty($row['email']))
  1421.                     $errors0[] = $lang->advinvsys_resend_err2;
  1422.             }
  1423.  
  1424.             // daca nu au aparut erori?!
  1425.             if (count($errors0) == 0) {
  1426.                 // se va retrimite invitatia catre adresa de e-mail specificata
  1427.                 $body = nl2br($mybb->settings['advinvsys_setting_sendemail']);
  1428.                 $message = $parser->parse_message($message, array(
  1429.                     'allow_html' => 0,
  1430.                     'allow_smilies' => 0,
  1431.                     'allow_mycode' => 1,
  1432.                     'filter_badwords' => 1
  1433.                         ));
  1434.                 $key = $row['code'];
  1435.                 my_mail($row['email'], 'Invitation', $AISDevelop->parseBody($body, $key, $message),
  1436.                         '', '', '', false, 'html');
  1437.  
  1438.                 // sa nu uitam sa facem update la data trimiterii invitatiei
  1439.                 $db->update_query('advinvsys_codes', array('date' => TIME_NOW),
  1440.                         'cid = \'' . $cid . '\'');
  1441.  
  1442.                 $plugins->run_hooks('advinvsys_mainpage_do_resend_end');
  1443.  
  1444.                 // se va face redirectionarea
  1445.                 redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1446.                         $lang->sprintf($lang->advinvsys_resend_succ, $row['email']));
  1447.             } else {
  1448.                 // se afiseaza erorile frumos pe ecran
  1449.                 $errors0 = inline_error($errors0);
  1450.             }
  1451.         } else if (isset($mybb->input['type'])
  1452.                 && $mybb->input['type'] == 'giveback') {
  1453.             // se verifica autenticitatea cererii
  1454.             if (!isset($mybb->input['my_post_key']) ||
  1455.                     $mybb->post_code != $mybb->input['my_post_key']) {
  1456.                 $errors0[] = $lang->advinvsys_errors_invalidreq;
  1457.             }
  1458.  
  1459.             $cid = intval($mybb->input['id']);
  1460.  
  1461.             $plugins->run_hooks('advinvsys_mainpage_do_takeback_start');
  1462.  
  1463.             $expr = (is_numeric($mybb->settings['advinvsys_setting_dateexpr'])) ?
  1464.                 abs($mybb->settings['advinvsys_setting_dateexpr']) : 7;
  1465.             $query = $db->simple_select('advinvsys_codes', '*', 'date < ' .
  1466.                     intval(TIME_NOW - $expr * 86400) .
  1467.                     ' AND cid = ' . intval($cid));
  1468.            
  1469.             if ($db->num_rows($query) == 0) {
  1470.                 // invitatia nu a expirat sau ea nu exista in sistem
  1471.                 $errors0[] = $lang->advinvsys_giveback_err1;
  1472.             } else {
  1473.                 // daca exista cel putin o invitatie
  1474.                 $row = $db->fetch_array($query);
  1475.                 // verificam daca invitatia apartine userului curent
  1476.                 if (intval($row['did']) != $mybb->user['uid']) {
  1477.                     $errors0[] = $lang->advinvsys_giveback_err2;
  1478.                 }
  1479.             }
  1480.  
  1481.             // daca se ajunge aici atunci totul e in regula
  1482.             if (count($errors0) == 0) {
  1483.                 // se sterge invitatia din baza de date
  1484.                 $db->delete_query('advinvsys_codes', 'cid = \'' . intval($cid) . '\'');
  1485.  
  1486.                 $plugins->run_hooks('advinvsys_mainpage_do_takeback_end');
  1487.  
  1488.                 if ($mybb->settings['advinvsys_setting_giveexpr'] == 1) {
  1489.                     // se acorda o invitatie
  1490.                     $AISDevelop->addInvitations('uid', $row['did'], 1);
  1491.  
  1492.                     // redirect
  1493.                     redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1494.                             $lang->advinvsys_giveback_succ1);
  1495.                 } else {
  1496.  
  1497.                     // se face redirectionarea
  1498.                     redirect($mybb->settings['bburl'] . '/usercp.php?action=advinvsys',
  1499.                             $lang->advinvsys_giveback_succ2);
  1500.                 }
  1501.             } else {
  1502.                 // se afiseaza erorile frumos pe ecran
  1503.                 $errors0 = inline_error($errors0);
  1504.             }
  1505.         }
  1506.        
  1507.         // un extraheader este adaugat
  1508.         eval("\$extraheader = \"" . $templates->get("advinvsys_preview_header") . "\";");
  1509.         $content .= $errors0;
  1510.  
  1511.         $plugins->run_hooks('advinvsys_mainpage_top');
  1512.  
  1513.         // se realizeaza paginarea in vederea afisarii primului tabel
  1514.         $per_page = 10; // in mod implicit
  1515.         if ($mybb->input['page'] && intval($mybb->input['page']) > 1) {
  1516.             $mybb->input['page'] = intval($mybb->input['page']);
  1517.             $start = ($mybb->input['page'] * $per_page) - $per_page;
  1518.         } else {
  1519.             $mybb->input['page'] = 1;
  1520.             $start = 0;
  1521.         }
  1522.  
  1523.         // se obtine id-ul utilizatorului curent
  1524.         $uid = $mybb->user['uid'];
  1525.  
  1526.         // acum paginarea este in regula, se trece la obtinerea datelor din tabel
  1527.         $query = $db->simple_select('advinvsys_codes', 'COUNT(cid) AS total',
  1528.                 'did = \'' . $uid . '\'');
  1529.         // variabila ce retine numarul de randuri obtinute din interogare
  1530.         $total_rows = $db->fetch_field($query, 'total');
  1531.  
  1532.         // tabelul cu invitatii create
  1533.         $table = new AISTable;
  1534.         $table->construct_header($lang->advinvsys_created_email, array('width' => '25%'));
  1535.         $table->construct_header($lang->advinvsys_created_code, array('width' => '35%'));
  1536.         $table->construct_header($lang->advinvsys_created_date, array('width' => '15%'));
  1537.         $table->construct_header($lang->advinvsys_created_expr, array('width' => '15%'));
  1538.         $table->construct_header($lang->advinvsys_created_acts, array('width' => '10%', 'class' => 'align_center'));
  1539.  
  1540.         // se creaza interogarea
  1541.         $query = $db->simple_select('advinvsys_codes', '*', 'did = \'' . $uid . '\'',
  1542.                 array('order_by' => 'date', 'order_dir' => 'DESC', 'limit' => $start . ',' . $per_page));
  1543.         $expiration_days = (is_numeric($mybb->settings['advinvsys_setting_dateexpr']))
  1544.             ? abs($mybb->settings['advinvsys_setting_dateexpr'])
  1545.             : 7;
  1546.         // se creaza tabelul rand cu rand
  1547.         while ($row = $db->fetch_array($query)) {
  1548.             $table->construct_cell((empty($row['email']) ? '-' : $row['email']), array('class' => 'align_center'));
  1549.             $table->construct_cell($row['code'], array('class' => 'align_center'));
  1550.             $table->construct_cell(my_date($mybb->settings['dateformat'], intval($row['date']), '', false), array('class' => 'align_center'));
  1551.             $date_expr = strtotime('+' . $expiration_days . ' day', intval($row['date']));
  1552.             $table->construct_cell(my_date($mybb->settings['dateformat'], $date_expr, '', false), array('class' => 'align_center'));
  1553.             $table->construct_cell('<a href="usercp.php?action=advinvsys&amp;type=giveback&amp;id=' . intval($row['cid']) . '&amp;my_post_key=' . $mybb->post_code . '" class="tooltip"><img src="./images/advinvsys/getback.gif"/><span>' . $lang->advinvsys_created_getback . '</span></a>&#160;<a href="usercp.php?action=advinvsys&amp;type=resend&amp;id=' . intval($row['cid']) . '&amp;my_post_key=' . $mybb->post_code . '" class="tooltip"><img src="./images/advinvsys/resend.gif"/><span>' . $lang->advinvsys_created_resend . '</span></a>', array('class' => 'align_center'));
  1554.             $table->construct_row();
  1555.         }
  1556.  
  1557.         // in cazul in care nu a existat niciun rand intors din baza de date atunci se afiseaza un mesaj central
  1558.         if ($table->num_rows() == 0) {
  1559.             $table->construct_cell($lang->advinvsys_created_noinvs, array('class' => 'align_center', 'colspan' => 5));
  1560.             $table->construct_row();
  1561.         }
  1562.  
  1563.         // in final se afiseaza tabelul pe ecranul utilizatorului
  1564.         $content .= $table->construct_html($lang->advinvsys_created_title . '<div style=\'float: right;\'><a href=\'usercp.php?action=advinvsys&amp;method=send\' class=\'advinvsys_send_button\' id=\'advinvsys_send_button\'>&nbsp;</a></div>');
  1565.         // se realizeaza paginarea
  1566.         $content .= multipage($total_rows, $per_page, $mybb->input['page'], "usercp.php?action=advinvsys&amp;page={page}");
  1567.  
  1568.         $plugins->run_hooks('advinvsys_mainpage_middle');
  1569.  
  1570.         // formularul de trimitere a unei invitatii prin email
  1571.         $codebuttons = build_mycode_inserter();
  1572.         eval("\$invite_form = \"" . $templates->get("advinvsys_invite_form") . "\";");
  1573.         $content .= $invite_form;
  1574.  
  1575.         // formularul de cumparare a unor invitatii
  1576.         $options = '<option value="-">Choose one gateway</option>';
  1577.         $cost = array();
  1578.  
  1579.         // daca exista NewPoints instalat in system!
  1580.         if ($mybb->settings['advinvsys_setting_newpointsenable'] == 1 &&
  1581.                 $AISDevelop->isInstalled('newpoints')) {
  1582.             $options .= '<option value="newpoints">NewPoints</option>';
  1583.             $cost['newpoints']['cost'] = (is_numeric($mybb->settings['advinvsys_setting_newpointscost'])) ?
  1584.                 floatval($mybb->settings['advinvsys_setting_newpointscost']) : 10;
  1585.             $cost['newpoints']['currency'] = (!empty($mybb->settings['newpoints_main_curname'])) ?
  1586.                 $mybb->settings['newpoints_main_curname'] : 'Points';
  1587.         }
  1588.  
  1589.         // este activa plata prin Paypal
  1590.         if (!empty($mybb->settings['advinvsys_setting_paypalemail']) &&
  1591.                 filter_var($mybb->settings['advinvsys_setting_paypalemail'], FILTER_VALIDATE_EMAIL)) {
  1592.             $options .= '<option value="paypal">Paypal</option>';
  1593.             $cost['paypal']['cost'] = (is_numeric($mybb->settings['advinvsys_setting_paypalcost'])) ?
  1594.                 floatval($mybb->settings['advinvsys_setting_paypalcost']) : 1;
  1595.             $cost['paypal']['currency'] = $mybb->settings['advinvsys_setting_paypalcurr'];
  1596.         }
  1597.  
  1598.         // este activ sistemul de plata prin SMS
  1599.         if ($mybb->settings['advinvsys_setting_smsenable'] == 1 &&
  1600.                 !empty($mybb->settings['advinvsys_setting_smssecret']) &&
  1601.                 !empty($mybb->settings['advinvsys_setting_smsid']) &&
  1602.                 !empty($mybb->settings['advinvsys_setting_smssig'])) {
  1603.             $options .= '<option value="fortumo">SMS - Fortumo</option>';
  1604.         }
  1605.        
  1606.         // se ofera posibilitatea de a se adauga si alte sisteme de plata
  1607.         $plugins->run_hooks('advinvsys_payment_add');
  1608.  
  1609.         if (!empty($options)) {
  1610.             $options1 = '<select name="number" id="number" size="1"><option value="-">Chose one value  </option>';
  1611.             $array = explode(',', $mybb->settings['advinvsys_setting_packages']);
  1612.             foreach ($array as $value) {
  1613.                 if (is_numeric($value) && $value > 0) {
  1614.                     $options1 .= '<option value="' . $value . '">' . $value . '</option>';
  1615.                 }
  1616.             }
  1617.             $options1 .= '</select>';
  1618.            
  1619.             $plugins->run_hooks('advinvsys_payment_javascript');
  1620.            
  1621.             $extraheader .= '<script type="text/javascript">
  1622.            Array.prototype.contains = function(element) {
  1623.                for (var i = 0; i < this.length; i++)
  1624.                    if (this[i] == element)
  1625.                        return i;
  1626.                return -1;
  1627.            };
  1628.            Event.observe(document, "dom:loaded", function() {
  1629.                function checkNumber() {
  1630.                    var value = $(\'number\').getValue();
  1631.                    var gateway = $(\'gateway\').getValue();
  1632.                    switch (value) {
  1633.                        case "-" :
  1634.                            $(\'price\').value = \'0\';
  1635.                            $(\'currency\').innerHTML = \'EUR\';
  1636.                            $(\'buy_submit\').hide();
  1637.                            break;
  1638.                        default :
  1639.                            // newpoints / paypal / SMS
  1640.                            if (gateway == "paypal") {
  1641.                                $(\'price\').value = parseFloat(value) * parseFloat(' . (isset($cost['paypal']['cost']) ? $cost['paypal']['cost'] : 0) . ');
  1642.                                $(\'currency\').innerHTML = \'' . (isset($cost['paypal']['currency']) ? $cost['paypal']['currency'] : 'EUR') . '\';
  1643.                                $(\'special_line\').innerHTML = \'<td class="trow2" colspan="2"><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"/><input type="hidden" name="business" value="' . $mybb->settings['advinvsys_setting_paypalemail'] . '"/><input type="hidden" name="amount" value="\' + $(\'price\').getValue() + \'"><input type="hidden" name="currency_code" value="' . (isset($cost['paypal']['currency']) ? $cost['paypal']['currency'] : 'EUR') . '"/><input type="hidden" name="item_name" value="Buy Invitations"/><input type="hidden" name="item_number" value="' . $mybb->user['uid'] . '"/><input type="hidden" name="image_url" value="' . $theme['logo'] . '"/><input type="hidden" name="no_shipping" value="1"/><input type="hidden" name="notify_url" value="' . $mybb->settings['bburl'] . '/inc/plugins/advinvsys/paypal_gateway.php"/><input type="hidden" name="return" value="' . $mybb->settings['bburl'] . '/"/><input type="hidden" name="cancel_return" value="' . $mybb->settings['bburl'] . '"/><center><input type="image" src="images/advinvsys/paypal_button.gif" border="0" name="submit" alt="Make payments with PayPal!"/></center></form></td>\';          
  1644.                                $(\'special_line\').show();
  1645.                                $(\'buy_submit\').hide();
  1646.                            }
  1647.                            else if (gateway == "newpoints") {
  1648.                                $(\'price\').value = parseFloat(value) * parseFloat(' . (isset($cost['newpoints']['cost']) ? $cost['newpoints']['cost'] : 0) . ');
  1649.                                $(\'currency\').innerHTML = \'' . (isset($cost['newpoints']['currency']) ? $cost['newpoints']['currency'] : 'EUR') . '\';
  1650.                                $(\'buy_submit\').show();
  1651.                            }                    
  1652.                    }
  1653.                }
  1654.                // se verifica daca valoarea introdusa ca suma este intreaga
  1655.                $(\'gateway\').observe(\'change\', function() {
  1656.                    var value = this.getValue();
  1657.                    switch (value) {
  1658.                        case "-" :
  1659.                            $(\'number\').innerHTML = \'<option value="-">Chose one value  </option>\';
  1660.                            $(\'special_line\').hide();
  1661.                            break;
  1662.                        case "fortumo" :
  1663.                            //$(\'special_line\').innerHTML = \'' . $lang->advinvsys_buy_smscountry . '\';
  1664.                            new Ajax.Request(\'xmlhttp.php?action=ais_smsfortumo\', {
  1665.                                method: \'post\',
  1666.                                onCreate: function() {
  1667.                                    $(\'special_line\').innerHTML = \'<td class="trow2" colspan="2" align="center"><img src="images/advinvsys/load.gif"/></td>\';
  1668.                                    $(\'special_line\').show();
  1669.                                },
  1670.                                onComplete: function(data) {
  1671.                                    text = data.responseText.replace(/(\r\n|\n|\r)/gm, "");
  1672.                                    if(text.match(/<success>(.*)<\/success>/)) {
  1673.                                        htmlb = text.match(/<success>(.*)<\/success>/);
  1674.                                        $(\'special_line\').innerHTML = \'<td class="trow2" colspan="2">\'
  1675.                                            + htmlb[0] + \'</td>\';
  1676.                                    }
  1677.                                }
  1678.                            });
  1679.                            break;
  1680.                        case "newpoints" :
  1681.                            // newpoints
  1682.                            $(\'number\').innerHTML = \'' . $options1 . '\';
  1683.                            $(\'special_line\').innerHTML = \'\' ;
  1684.                            $(\'special_line\').hide();
  1685.                            break;
  1686.                        case "paypal" :
  1687.                            // paypal
  1688.                            $(\'number\').innerHTML = \'' . $options1 . '\';
  1689.                            break;
  1690.                    }
  1691.                    checkNumber();
  1692.                });
  1693.                $(\'number\').observe(\'change\', checkNumber);
  1694.                checkNumber();
  1695.                // in mod implicit se ascunde randul
  1696.                $(\'special_line\').hide();
  1697.            });
  1698.            </script>';
  1699.             eval("\$buy_form = \"" . $templates->get("advinvsys_buy_form") . "\";");
  1700.             $content .= '<br/>' . $buy_form;
  1701.         }
  1702.     }
  1703.  
  1704.     $plugins->run_hooks('advinvsys_mainpage_down');
  1705.  
  1706.     // se evalueaza sablonul curent
  1707.     eval("\$page = \"" . $templates->get("advinvsys_standard_page") . "\";");
  1708.     // in fine, codul HTML e afisat pe ecran
  1709.     output_page($page);
  1710. }
  1711.  
  1712. // Se incarca toate modulele activate pentru aceasta modificare
  1713. function advinvsys_load_modules() {
  1714.     global $cache, $plugins, $mybb, $theme, $db, $templates;
  1715.  
  1716.     // se intoarce lista cu modulele active
  1717.     $modules = $cache->read("advinvsys_modules");
  1718.  
  1719.     $plugins->run_hooks('advinvsys_modules_do_load');
  1720.  
  1721.     if (is_array($modules['active'])) {
  1722.  
  1723.         // pentru fiecare modul din lista
  1724.         foreach ($modules['active'] as $module) {
  1725.             if ($module != "" && file_exists(MYBB_ROOT . "inc/plugins/advinvsys/plugins/" . $module . ".php")) {
  1726.                 require_once MYBB_ROOT . "inc/plugins/advinvsys/plugins/" . $module . ".php";
  1727.             }
  1728.         }
  1729.     }
  1730. }
  1731.  
  1732. // Functia de tip handler pentru partea de administrare
  1733. function advinvsys_admin_action_handler(&$action) {
  1734.     // se adauga o noua actiune in vectorul cu acelasi nume
  1735.     $action['advinvsys'] = array('active' => 'advinvsys', 'file' => 'advinvsys.php');
  1736. }
  1737.  
  1738. // Functia care adauga un nou link in cadrul meniului paginii de administrare intitulata "Configuration"
  1739. function advinvsys_admin_menu(&$sub_menu) {
  1740.     global $lang;
  1741.  
  1742.     // se incarca fisierul de limba al modificarii
  1743.     $lang->load("advinvsys");
  1744.  
  1745.     // se realizeaza prelucrarile de date
  1746.     end($sub_menu);
  1747.     $key = (key($sub_menu)) + 10;
  1748.     if (!$key) {
  1749.         $key = '50';
  1750.     }
  1751.  
  1752.     $sub_menu[$key] = array('id' => 'advinvsys', 'title' => $lang->advinvsys_modname,
  1753.         'link' => "index.php?module=config-advinvsys");
  1754. }
  1755.  
  1756. // Functia care mai adauga inca un tab in cadrul sectiunii de editare a unui grup din Admin CP
  1757. function advinvsys_admin_groups_edit_tab($tabs) {
  1758.     global $lang;
  1759.  
  1760.     // se include fisierul de limba
  1761.     $lang->load("advinvsys");
  1762.  
  1763.     // se adauga tab-ul in sistem
  1764.     $tabs['advinvsys'] = $lang->advinvsys_tabs_groups;
  1765. }
  1766.  
  1767. // Functia care afiseaza tab-ul
  1768. function advinvsys_admin_groups_edit() {
  1769.     global $lang, $form, $mybb, $plugins, $AISDevelop;
  1770.  
  1771.     echo "<div id=\"tab_advinvsys\">";
  1772.     $form_container = new FormContainer($lang->advinvsys_tabs_groups);
  1773.  
  1774.     $form_container->output_row($lang->advinvsys_tabs_groups_maxinv,
  1775.             $lang->advinvsys_tabs_groups_maxinv_desc,
  1776.             $form->generate_text_box('max_invitations',
  1777.                 $AISDevelop->truncNumber($mybb->input['max_invitations']),
  1778.                 array('id' => 'max_invitations')),
  1779.             'max_invitations');
  1780.  
  1781.     $plugins->run_hooks('advinvsys_groups_edit');
  1782.  
  1783.     $form_container->end();
  1784.     echo "</div>";
  1785. }
  1786.  
  1787. // Functia care salveaza datele din cadrul tab-ului creat cu ajutorul fct. de mai sus
  1788. function advinvsys_admin_groups_edit_save() {
  1789.     global $mybb, $updated_group, $plugins, $AISDevelop;
  1790.  
  1791.     $updated_group['max_invitations'] = $AISDevelop->truncNumber($mybb->input['max_invitations']);
  1792.  
  1793.     $plugins->run_hooks('advinvsys_groups_do_edit');
  1794. }
  1795.  
  1796. // Functia care verifica daca e posibila o consersie unor puncte NewPoints
  1797. // (etc.) in invitatii
  1798. function advinvsys_check_convert($uid, $amount, $system = 'newpoints') {
  1799.     global $mybb, $db, $plugins, $AISDevelop;
  1800.  
  1801.     try {
  1802.         if ($amount <= 0 || $uid <= 0)
  1803.             return;
  1804.  
  1805.         // ce sistem se foloseste ?
  1806.         if ($system == 'newpoints') {
  1807.             $userid = $mybb->user['uid'];
  1808.  
  1809.             if ($userid == $uid) {
  1810.                 if ($amount > $mybb->user['newpoints'])
  1811.                     return false;
  1812.                 else
  1813.                     return $mybb->user['newpoints'];
  1814.             }
  1815.             else {
  1816.                 // se realizeaza o noua interogare
  1817.                 $query = $db->simple_select('users', 'newpoints', 'uid = \'' .
  1818.                         intval($uid) . '\' AND newpoints >= ' . $AISDevelop->truncNumber($amount), array('limit' => 1));
  1819.  
  1820.                 if ($row = $db->fetch_array($query))
  1821.                     return $AISDevelop->truncNumber($row['invitations']);
  1822.                 else
  1823.                     return false;
  1824.             }
  1825.         } else {
  1826.             // altfel se da posibilitatea adaugarii unui alt sistem de convertire
  1827.             $plugins->run_hooks('advinvsys_convert_do_check');
  1828.         }
  1829.     } catch (Exception $e) {
  1830.         return false;
  1831.     }
  1832. }
  1833.  
  1834. // Functia care realizeaza consersia unor puncte NewPoints (etc.) in invitatii
  1835. function advinvsys_take_convert($uid, $points, $system = 'newpoints') {
  1836.     global $db, $mybb, $plugins, $advinvsys_queries;
  1837.  
  1838.     if ($points == 0 || $uid <= 0)
  1839.         return;
  1840.  
  1841.     if ($system == 'newpoints') {
  1842.         $advinvsys_queries[] = "UPDATE " . TABLE_PREFIX . "users SET newpoints = newpoints - '"
  1843.                 . floatval(round($points, intval($mybb->settings['newpoints_main_decimal']))) . "'
  1844.                WHERE uid = '" . intval($uid) . "'";
  1845.  
  1846.         // se va executa mai tarziu
  1847.         add_shutdown('advinvsys_run_queries');
  1848.     } else {
  1849.         // pentru alte sisteme
  1850.         $plugins->run_hooks('advinvsys_convert_do_take');
  1851.     }
  1852. }
  1853.  
  1854. // Functia care ruleaza mai multe interogari cu baza de date deodata
  1855. function advinvsys_run_queries() {
  1856.     global $db, $advinvsys_queries;
  1857.  
  1858.     // pentru fiecare interogare
  1859.     foreach ($advinvsys_queries as $key => $query)
  1860.         $db->write_query($query);
  1861.  
  1862.     // la final vectorul de interogari devine null
  1863.     unset($advinvsys_queries);
  1864. }
  1865.  
  1866. // Functia care intoarce datele necesare platii prin SMS-Fortumo
  1867. function advinvsys_get_sms_data($url, $code, $err1, $err2) {
  1868.     global $lang, $templates;
  1869.     try {
  1870.         $lang->load("advinvsys");
  1871.        
  1872.         $xml = simplexml_load_file($url);
  1873.  
  1874.         // totul e bine
  1875.         // cautam tara specificata in lista
  1876.         $i = 0;
  1877.  
  1878.         foreach ($xml->xpath(sprintf('/services_api_response/service/countries/country[@approved="true" and @code="%s"]', $code)) as $country) {
  1879.             $promotional = $country->promotional_text->english;
  1880.             if ($promotional == '')
  1881.                 $promotional = $country->promotional_text->local;
  1882.  
  1883.             $promotional = str_replace('Support', '<br>Support', $promotional);
  1884.             $promotional = str_replace('Mobile', '<br>Mobile', $promotional);
  1885.  
  1886.             $plugins->run_hooks('advinvsys_sms_do_check');
  1887.  
  1888.             $keyword = $country->prices->price->message_profile->attributes()->keyword;
  1889.             $shortcode = $country->prices->price->message_profile->attributes()->shortcode;
  1890.             $country = $country->attributes()->name;
  1891.            
  1892.             eval("\$result = \"" . $templates->get('advinvsys_sms_buy') . "\";");
  1893.             return $result;
  1894.  
  1895.             $i = 1;
  1896.             break;
  1897.         }
  1898.         if ($i == 0) {
  1899.             return "<center>{$err1}</center>";
  1900.         }
  1901.     } catch (Exception $ex) {
  1902.         return "<center>{$err2}</center>";
  1903.     }
  1904. }
  1905.  
  1906. // Functia care intoarce codul tarii din care provine un utilizator
  1907. function advinvsys_country_recognition($ip) {
  1908.     // se incearca gasirea tarii din care este vizitatorul
  1909.     $url = 'http://api.hostip.info/country.php?ip=' . $ip;
  1910.  
  1911.     // se va folosi api-ul celor de la HostIP
  1912.     $country = @file_get_contents($url);
  1913.  
  1914.     // codul nu poate avea mai mult de 5 litere
  1915.     if (!empty($country) && strlen($country) < 5) {
  1916.         return $country;
  1917.     } else {
  1918.         return 'XX';
  1919.     }
  1920. }
  1921. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement