updateConfig();
            break;
        case 'update_feedback':
            updateFeedback();
            break;
        case 'update_password':
            $passwordError = updatePassword($_POST['admin_password']);
            break;
        case 'update_translation':
            updateTranslation();
            break;
        case 'update_theme':
            updateTheme();
            break;
        case 'update_channels':
            updateChannels();
            break;
        case 'total_reset':
            $total_reset = totalReset();
            break;
    }
}
if (array_key_exists('delete', $_GET) && $_GET['delete'] == 'key') {
    removeLicenseKey();
}
/****************************************************************************
* Template > Header
*****************************************************************************/
?>
<!DOCTYPE HTML>
<html>
Exemple #2
0
function updateChannels($id, $unit = false)
{
    check_logged_in();
    global $user, $mysqli;
    $channelquery = $unit === true ? 'SELECT channelId FROM ChannelUnits WHERE unitId = ?' : 'SELECT parent FROM Channels WHERE id = ?';
    // then for channels
    $sql = 'INSERT INTO ChannelProgress (userId,channelId,progress)
				SELECT ?, c.id,
				((
					SELECT COALESCE(SUM(p.progress),0) FROM ChannelProgress p
					JOIN Channels c1 ON c1.id = p.channelId
					WHERE c1.parent = c.id AND p.userId=?
				)
				+
				(
					SELECT COALESCE(SUM(p.correct) / SUM(p.layers),0) FROM UnitProgress p
					JOIN ChannelUnits u ON u.unitId = p.unitId
					WHERE u.channelId = c.id AND p.userId=?
				))
				/
				((
					SELECT COUNT(*) FROM Channels c1
					WHERE c1.parent = c.id
				)
				+
				(
					SELECT COUNT(*) FROM ChannelUnits u
					WHERE u.channelId = c.id
				))
				FROM Channels c
				WHERE c.id IN (' . $channelquery . ')
			ON DUPLICATE KEY UPDATE 
			progress=VALUES(progress)';
    /* Prepared statement, stage 1: prepare */
    if (!($stmt = $mysqli->prepare($sql))) {
        echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
    }
    $userid = $user->userid();
    $stmt->bind_param('iiii', $userid, $userid, $userid, $id);
    $res = $stmt->execute();
    $stmt->close();
    // upper channels
    $stmt = $mysqli->prepare($channelquery);
    $stmt->bind_param('i', $id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($parent);
    // try to fetch
    while ($stmt->fetch()) {
        updateChannels($parent);
    }
    $stmt->free_result();
    $stmt->close();
}