<?php
/******************************************************************************/
//                                                                            
//								{title}                                      
//							http://{author_url}                                   
//					produced by {author_name}, {author_email}                  
//							LICENSED BY ONECUBE                            	  
//                                                                            
/******************************************************************************/

$file_dir = '{type_url}';
	if (file_exists($file_dir)) {
		$mdp = hash_file('sha1', $file_dir);
		if ($mdp !== 'e244e792bfc84d121d41251c77601a4e03bc5467') { cmsCore::error404(); die(); }
	}
	else { cmsCore::error404(); die(); }

class onecube{Name} extends cmsOnecube { }

	$protect = new onecube{Name};

			$core = cmsCore::getInstance();
			$protect->query_key = "select `license_key` from `{#}{name}_key` where `key`='local_key'";
			$protect->query_res = $core->db->query($protect->query_key);
			$protect->query_row = $core->db->fetchAssoc($protect->query_res);
			$lkey = $protect->query_row['license_key'];
	
		if(empty($lkey) or !empty($_GET['newkey'])==1) {
		
			if(empty($_POST['license_key'])) {
			
				if (cmsUser::isAdmin()) {  	
			
					echo '<div id="popup-manager" class="popup-show">
							<div class="nyroModalBg" style="opacity: 0.7;"></div>
									<div class="nyroModalCont" style="position: fixed; width: auto; height: auto; top: 0px; left: 435.5px; overflow: auto;">
										<div class="nyroModalLink"><script type="text/javascript" rel="forceLoad" src="/templates/default/js/jquery-chosen.js"></script>
											<link rel="stylesheet" type="text/css" href="/templates/default/controllers/admin/styles.css">
											<div class="modal_form">
												<h1 class="nyroModalTitle nmReposition" style="max-width: 652px; position: fixed; top: 5px; left: 465.5px;">Активация</h1>
												<form id="FormOneCube" action="?newkey=1" method="post" style="padding: 10px;">
													<p>Введите лицензионный ключ:<b></b><br/>
													<input name="license_key" class="input" id="title" required="" type="text" size="35"/>
													<input class="button-submit" id="submit1" type="submit" name="submitButton" value="Активировать" title="Активировать">
													</p>
												</form>			
											</div>
										</div>
									</div>
								</div>
							</div>	
						</div>';
				}
				else { cmsCore::error404(); die(); }
			} 
			
			else {	
					$key = trim($_POST['license_key']);
					$core = cmsCore::getInstance();
		        	$core->db->query("update `{#}{name}_key` set `value`='',`license_key`='' where `key`='local_key'");
		  
						$protect->license_key = $key;  
						$protect->api_server = '{domain}/onecube';
						$protect->secret_key = '{key_addon}';
						$protect->addon_name = '{name}';
						$protect->licenseurl();
						$protect->validate();

						if ($protect->errors) { 
							if(!$lkey) { 
								cmsUser::addSessionMessage('Шаблон не активирован', 'error');
								echo '<div id="popup-manager" class="popup-show">
										<div class="nyroModalBg" style="opacity: 0.7;"></div>
											<div class="nyroModalCont" style="position: fixed; width: auto; height: auto; top: 0px; left: 435.5px; overflow: auto;">
												<div class="nyroModalLink"><script type="text/javascript" rel="forceLoad" src="/templates/default/js/jquery-chosen.js"></script>
													<link rel="stylesheet" type="text/css" href="/templates/default/controllers/admin/styles.css">
													<div class="modal_form">
														<h1 class="nyroModalTitle nmReposition" style="max-width: 652px; position: fixed; top: 5px; left: 465.5px;">Активация</h1>
															<form action="" method="post" style="padding: 10px;">
															<input class="button-submit" id="submit" type="submit" value="Активировать повторно" title="Активировать повторно">
														</form>			
													</div>
												</div>
											</div>
									</div>';
							}
						}
						else {
							
		        		$core->db->query("update `{#}{name}_key` set `license_key`='".$key."' where `key`='local_key'");	
						
						if($core->db->affectedRows()==0) { echo "Ошибка: 1."; }
						if ($mysql_error=$core->db->error()) { echo "Ошибка: 2"; }
						
							echo '<div id="popup-manager" class="popup-show">
									<div class="nyroModalBg" style="opacity: 0.7;"></div>
										<div class="nyroModalCont" style="position: fixed; width: auto; height: auto; top: 0px; left: 435.5px; overflow: auto;">
											<div class="nyroModalLink"><script type="text/javascript" rel="forceLoad" src="/templates/default/js/jquery-chosen.js"></script>
												<link rel="stylesheet" type="text/css" href="/templates/default/controllers/admin/styles.css">
												<div class="modal_form">
													<h1 class="nyroModalTitle nmReposition" style="max-width: 652px; position: fixed; top: 5px; left: 465.5px;">Активация</h1>
													<div style="padding: 10px;">Поздравляем! Шаблон успешно активирован. <br><br><span style="font-size:18px;"><a href="{name}">Перейти к использованию<a/></span></div>	
												</div>
											</div>
										</div>
									</div>';
							cmsUser::addSessionMessage('Шаблон успешно активирован', 'success');
						}
			}		
		} 
		
	    $protect = new onecube{Name};
	    $protect->license_key = $lkey;
	    $protect->api_server = '{domain}/onecube';
	    $protect->secret_key = '{key_addon}';
		$protect->addon_name = '{name}';
		$protect->licenseurl();
	    $protect->validate();
	
		   if (!$protect->errors) {
		    	cmsUser::addSessionMessage('Лицензия активна | Ключ: '.$lkey, 'success');
		   } 
		    
		unset($protect);
	    
?>